• 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

How to remove and insert entity in same transaction?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a requirement in which I create some relationship between two object from GUI. So I have a list grid kind of thing where I can add multiple objects to top object in page.
Now say there was a relationship already from A to B and A to C and A to D for A object.
I go and delete A to B from gui and again add B .
Now I can perform all three actions at same go. Update , remove and add new relationship and save them.
I pass 3 lists of new, updated and removed relationship to my service bean and that bean in turn calls DAO methods in loop to remove, add or update the relationships.
My EntityManager is at DAO level.
There is a unique constraint which on ids of two objects (A and B in this case) at database table level .
Now what happens is that aafter all 3 actions when hibenrate tries to commit I get following exception.



So I believe some how even though i call getEntitymanager.remove(eObject) before getEntityManager.saveorupdate(eObj) , some how it is not geting cleared in 1st level cache and so I get this exception.
So can any one help how can I achieve removing and inserting same entity in a transaction in JPA / Hibernate?

Thanks

 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic