Skip to Main Content

Integration

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!

OneToMany is not working using composite key in JPA2.0 with Ecliselink

948590Oct 4 2012 — edited Oct 9 2012
Hi,

We are using JPA2.0 with Eclipselink, OneToMany relationship is not working when we are using composite key between two entities. Please find the problem in detail

Class Parent

@EmbeddedId
private ParentPK id;

@OneToMany(cascade = CascadeType.ALL, mappedBy="parents")
@JoinColumns(
{ @JoinColumn(name = "A", referencedColumnName = "A"),
@JoinColumn(name = "B", referencedColumnName = "B")})
private Set<Child> childList;

Class ParentPK

@Column(name = "A", nullable=false)
private String aData;

@Column(name = "B", nullable=false)
private String bData;

Note- parent table primary key is (A, B)


Class Child

@EmbeddedId
private ChildPK id;

@ManyToOne(optional = true)
@JoinColumns(
{ @JoinColumn(name = "A", referencedColumnName = "A", insertable = false, updatable = false),
@JoinColumn(name = "B", referencedColumnName = "B", insertable = false, updatable = false)})
private Parent parents;

Class ChildPK

@Column(name = "A", nullable=false)
private String aData;

@Column(name = "B", nullable=false)
private String bData;

@Column(name = "C", nullable=false)
private String cData;

Note- child table primary key is (A, B, C) and this has refernece to parent table with A, B foreighn key relationship.

I am trying simple entityManager find with Parent class and PArentPK

Parent parent = entityManager.find(Parent.class, parentPK);
System.out.println(" Child list ===> "+ parent.getChildList());

Child list is empty, we are not able to retrieve child list.

I tried all the combinations it is not working, Can some one please suggest us what could be the cause?

Thanks
Chandra
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 6 2012
Added on Oct 4 2012
6 comments
8,097 views