JPA: @JoinTable - Both columns are Primary Keys.. How do I stop that?

前端 未结 2 782
粉色の甜心
粉色の甜心 2021-01-16 18:14

This is my annotation I use to generate my Join Table.

@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = \"service_operations\", 
        joinColumns         


        
2条回答
  •  旧时难觅i
    2021-01-16 18:20

    This looks correct to me. Each row in the join table should identify a pair of workflow/service items. So (workflow_id, service_id) should be the primary key. Also workflow_id should be a foreign key into the workflow table and service_id should be a foreign key into the service table.

    Also note that a one-to-many association between A and B does not mean that an instance of A can have the same instance of B multiple times, rather an instance of A can have multiple distinct instances of B. For example a blog Post entity can have a one-to-many association with a Tag entity. This means that a blog Post P1 can have multiple tags Java, JPA, JavaEE, but can not have the same tag multiple times.

提交回复
热议问题