File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JPA self refrencing relationship problem...HELP Needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA self refrencing relationship problem...HELP Needed" Watch "JPA self refrencing relationship problem...HELP Needed" New topic
Author

JPA self refrencing relationship problem...HELP Needed

Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
I have this scenario, where i have three tables.

TABLE A has a_id (PK)
TABLE B has b_id (PK), c_id (FK), a_id (FK)
TABLE C has c_id (PK)

I am using JPA , now in Object terms, if i define the relationships, it is like







Now, if want to have class B as self referencing class, i.e If the Object of B will have an extra property of parentId, which refers to the different B object, then how to achieve that and code sample of how can i persist A object with all the relationships set to it directly by calling entityManager.saveobject(a);

example

A object contains collection of B objects which are say b1, b2, b3 and b2 and b3 object in that collection has parentId set as b1_id.
I want to save Object A such that all the records of B also gets saved normally without giving any transaction exception of transient object not being saved.

If anyone of you here can help me out in this, this will be really a great help.

regards
Akhil.

-------------------------------<br />you can't move ahead, unless you try for it.
 
Consider Paul's rocket mass heater.
 
subject: JPA self refrencing relationship problem...HELP Needed
 
Similar Threads
JPA: Cascade delete for join tables with composite key
@ManyToOne & @JoinColumn
Problem while using JPA, EJB 3.0
@ManyToOne & @JoinColumn
IllegalArgumentException: cannot remove/save a detached entity