• 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

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic