aspose file tools*
The moose likes Object Relational Mapping and the fly likes Problem with merge & persist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with merge & persist" Watch "Problem with merge & persist" New topic
Author

Problem with merge & persist

smitha eliz joshi
Greenhorn

Joined: Aug 30, 2012
Posts: 6
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

Joined: Mar 07, 2010
Posts: 1666
    
    7

Yes. Code similar to the below snippet is typically used for this purpose.



[How To Ask Questions][Read before you PM me]
smitha eliz joshi
Greenhorn

Joined: Aug 30, 2012
Posts: 6
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.
 
 
subject: Problem with merge & persist