Home » Eclipse Projects » EclipseLink » OneToMany is not working using composite key in JPA2.0 with Ecliselink(OneToMany is not working using composite key in JPA2.0 with Ecliselink)
OneToMany is not working using composite key in JPA2.0 with Ecliselink [message #933015] |
Thu, 04 October 2012 16:50 |
Chandra Narasimha Messages: 5 Registered: July 2012 |
Junior Member |
|
|
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
|
|
| |
Goto Forum:
Current Time: Thu Sep 26 06:03:58 GMT 2024
Powered by FUDForum. Page generated in 0.03221 seconds
|