aspose file tools*
The moose likes Object Relational Mapping and the fly likes org.hibernate.PersistentObjectException: detached entity passed to persist: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.PersistentObjectException: detached entity passed to persist: " Watch "org.hibernate.PersistentObjectException: detached entity passed to persist: " New topic
Author

org.hibernate.PersistentObjectException: detached entity passed to persist:

Unnikrishnan Rem
Greenhorn

Joined: Mar 21, 2009
Posts: 2
Sorry to edit post completely..

I got this exception when i submit a page second time in the same instance.
try the folowing if you get the same...

in your session bean
Check whether the entity instance is null
if (entity== null) {
em.persist(entity);// then use persist()
}
else{
entity= new Entity();
em.merge(entity);//other wise use merge()
}
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
In your code don't you mean ?

if (entity!= null) {
em.persist(entity);// then use persist()
}
else{
entity= new Entity();
em.merge(entity);//other wise use merge()
}

Because in your current version if entity is null you basically call em.persist(null) !


SCJP 5 , SCWCD 5, SCEA 5
Unnikrishnan Rem
Greenhorn

Joined: Mar 21, 2009
Posts: 2
The EntityManager persist(Object entity) API is used to mark a new instance for insert into the Database

Usage of the EntityManager AP

For the bean's first instance it does persist and for subsequent it should merge as already the identifier is in persistent state
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.hibernate.PersistentObjectException: detached entity passed to persist: