• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA - problem when an object refers to another object

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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?
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic