• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
}
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) !
 
Unnikrishnan Rem
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!