-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to persist a removed entity
PostPosted: Tue Sep 23, 2008 8:07 am 
Newbie

Joined: Tue Sep 23, 2008 7:44 am
Posts: 3
Location: Timisoara, Romania
Is there any way to persist a previously removed entity?

The following code throws PersistentObjectException: detached entity passed to persist.

EntityManager em;

// Create entity manager

MyEntity entity = new MyEntity();

em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();

em.getTransaction().begin();
em.remove(entity);
em.getTransaction().commit();

em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();

_________________
Bogdan Alexandru Caprarescu
http://bogdan.softinvent.org


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2008 6:29 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
merge() is supposed to reattach the bean to tbe session, independently of its current statr. Have you tried it?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 3:23 am 
Newbie

Joined: Tue Sep 23, 2008 7:44 am
Posts: 3
Location: Timisoara, Romania
Yes, I tried it (see bellow), but I have got the same exception.

EntityManager em;

// Create entity manager

MyEntity entity = new MyEntity();

em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();

em.getTransaction().begin();
em.remove(entity);
em.getTransaction().commit();

em.getTransaction().begin();
em.merge(entity);
em.getTransaction().commit();

em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 3:30 am 
Newbie

Joined: Tue Sep 23, 2008 7:44 am
Posts: 3
Location: Timisoara, Romania
I investigated how to persist a removed entity and here is a summary of what I found out: http://ideas.softinvent.org/2008/09/ang ... i-and.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.