Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA self refrencing relationship problem...HELP Needed

 
Akhil Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic