• 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

Problem with merge & persist

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am putting list of entities,

if I use persist for entire list, I am getting following
java.lang.Exception: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist:
because entity with same id exists in DB


if I use merge for entire list, I am getting following
java.lang.Exception: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not insert:
ORA-01400: cannot insert NULL into
because entity does not exists


does that mean I would need to check which entity exist & which not
and use appropriate method with entitymanager?


thanks & regards.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Code similar to the below snippet is typically used for this purpose.

 
smitha eliz joshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Bill,

Thank you for your reply.

Also, I am sorry for posting bad info in above case,
actually, Entity was written by someone else, and Id was @Generated; and since that id is based on combination of diff info, I need to set it in entity.
Once I commented @Gen annotation from Entity id, merge() works good for all entities in the list.

Thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic