• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA - problem when an object refers to another object  RSS feed

Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have the following object definition:

I then have a table PERSON with ID and NAME, and another table PERSON_TO_PERSON with PARENT_ID and CHILD_ID where PARENT_ID and CHILD_ID are FK to PERSON.ID

I have two problems:

My first problem (A) The following will enter two entries in PERSON_TO_PERSON rather then one.

The above will create two entries in PARENT_TO_PARENT with both entries have the same values, i.e.

My second problem (B) is that when I delete Ben, John - even after re-query for the object - still says Ben is his father. After I turn off/on the application John admits he has no father.

I tried to add the @ManyToMany with CascadeType.ALL However this simply deletes both Ben and John from the database.
I know I could also remove Ben from John however what if Ben had many other children? I need to loop through all the children too?
What if I have a requirement to add partners? Would I need to loop through the children and partners, delete Ben from all these, update all these
and than update Ben?
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!