openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <>
Subject Re: Locking Exception after Persisting new entity
Date Thu, 12 Nov 2009 18:02:40 GMT

Comments inline

On Thu, Nov 12, 2009 at 11:44 AM, Cil-Gamir <>wrote:

> Hi Daryl
> I'm not closing the entity manager, where should I do this ?

Well, when you're done using it.. From a quick look at your code you cache
the EntityManager in your DAO, but never call the setEntityManager method.
So you get a new instance of the EM each time you call getEntityManager().

I'd suggest updating your main test to cache the em. Something like this :
. . .
EntityManager em = getEntityManager();
em.persist(o);"############# CREATE START");
 . . .
em = getEntityManager()
 . . .

I'd avoid caching it in the DAO for the time being..

> I'm also not familiar with enhancing, my entity classes were declared as
> final, and JPA complained saying that it cannot do the enhancement for me
> if
> my classes are final.

<brief aside>
That's a limitation of the subclassing approach to enhancement. If you run
the stand-alone PCEnhancer tool you don't have to worry about final classes
</brief aside>

> If I want to do the build time enhancement, where is a good place to start
> to figure out how.
Here's a good place to start :

> The basic scenario is as follows.
> 1. I fetch an entity
> 2. I make a change to that entity and I save it (saving here involves
> creating a new entity as i'm trying to version rows in the database).
> 3. I fetch another different entity
> 4. upon trying to save that entity it fails.
> If I only save without persisting a new entity I can do that the whole day.
> but once I create a new entity the subsequent operation on any other entity
> or the newly saved one throws an optimistic locking exception
> --
> View this message in context:
> Sent from the OpenJPA Users mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message