Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with merge & persist

 
smitha eliz joshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic