• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

JPA self refrencing relationship problem...HELP Needed

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic