Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA @OneToMany Question

843830Jul 27 2008 — edited Jul 28 2008
Hello, there.

How can I set OneToMany relationship in JPA, when child's identity(uniqueness) needs parent's primary key?

Every books that I have only talk about the @PrimaryKeyJoinColumn with OneToOne mapping.
Every books that I have only talk about the @OneToMany mapping with non-identifying relationships.

Every google pages has no exception.

@Entity public class Parent implements Serializable {
    @Id public int id;
    @OneToMany public Collection<Child> child;
}

@Entity public class Child implements Serializable {

    @Id public int child_id;
    @ManyToOne Parent parent; // NOT FK, BUT PK ?????????????
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2008
Added on Jul 27 2008
2 comments
203 views