OneToMany is not working using composite key in JPA2.0 with Ecliselink [message #933015] |
Thu, 04 October 2012 12:50  |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.54640 seconds