tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Sébastien Scrève <jean-sebastien.scr...@atosorigin.com>
Subject Re: em.clear() in a non transactional context
Date Wed, 11 Feb 2009 10:44:04 GMT

Ok thanks David.

Let me explain the circumstances of my question :

I have a Stateful session bean. All methods are non transactional. I only
want to browse entities.

Let's say I have a reference to an entity. I call the clear() method on the
session bean. 
After that, it's still possible to browse my entity relations as the clear
method did nothing.

I really want to clear references to all entities to avoid memory leaks.

I know I can call getDelegate but this is not really a standard way to
proceed.
I'd like to have a standard answer to that question.

The specification says the clear() method make all entities detached. It
does not specify transactional conditions.

Any idea ? Don't you think you could remove the transaction test in the
clear() method ? Maybe the specification should clarify some things...

Thanks in advance !

Jean-Sébastien Scrève.


David Blevins wrote:
> 
> 
> On Feb 2, 2009, at 9:07 AM, Jean-Sébastien Scrève wrote:
> 
>> I have a question regarding the em.clear() in the JtaEntityManager  
>> class.
>> Before clearing the context, OpenEJB checks that a transaction is  
>> currently
>> active.
>> Is there any reason for that ? I don't see any mention of this  
>> behavior in
>> the specification.
> 
> It has to do with the lifecycle of a  
> PersistenceContextType.TRANSACTION EntityManager.  The long and short  
> of it is that the JtaEntityManager will create an EntityManager  
> (PersistenceContext) at the beginning of a transaction and destroy it  
> at the end of the transaction.  So when no transaction is active,  
> there is no EntityManager to call clear() on and no PersistenceContext  
> data to clear.
> 
> -David
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/em.clear%28%29-in-a-non-transactional-context-tp21793624p21951943.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Mime
View raw message