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.  [ 3 posts ] 
Author Message
 Post subject: immediate EntityManager.persist on removed entity
PostPosted: Tue Mar 17, 2009 5:56 pm 
Newbie

Joined: Tue Mar 17, 2009 5:46 pm
Posts: 3
Hi,

According to EBJ3 specification of persist method
Quote:
If X is a removed entity, it becomes managed.

I should be able to call persist(entity) immediate after remove(entity), but I'm receiving exception instead.

The code looks like this (em is an EntityManager):
Code:
Test t = new Test();
em.persist(t);
em.getTransaction().begin();
em.getTransaction().commit();
em.close();

em = GetEntityManager();
t = em.merge(t);
em.remove(t);
em.persist(t) <- here I got the exception


The Test class is just a simple entity with ID only.
I'm using the newest hibernate version with in SE environment.
The exception message is:
Quote:
Exception in thread "main" javax.persistence.EntityNotFoundException: deleted entity passed to persist:


Any help appreciated.


Top
 Profile  
 
 Post subject: Re: immediate EntityManager.persist on removed entity
PostPosted: Thu Apr 15, 2010 9:31 pm 
Newbie

Joined: Thu Apr 15, 2010 9:29 pm
Posts: 4
This is now created in JIRA as HHH-5124


Top
 Profile  
 
 Post subject: Re: immediate EntityManager.persist on removed entity
PostPosted: Sat Apr 17, 2010 6:13 pm 
Newbie

Joined: Thu Apr 15, 2010 9:29 pm
Posts: 4
I have now posted a patch to Hibernate Core for this problem, on the JIRA issue. For anyone interested in the fix, please evaluate the patch attached to the bug report:

Steps needed (see http://hibernate.org/sourcecode.html for details):
- Install Subversion and Maven 2 if you haven't already
- Fetch the Hibernate Core source tree (I did this against 3.5.1, but 3.3.x should be work as well)
- Patch the files using the patch ("HHH-5124.txt") in the JIRA issue
- Run 'mvn test' (this involves downloading apprx. half the internet)

This will also provide you with jar files in the various 'target' folders, so you could try out the patched jars in your own projects.

Hope this helps,
Jesper


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.