[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-2803) In specific cases, a closed entitymanager is injected by seam, resulting in illegalstateexceptions

Indrek Altpere (JIRA) jira-events at lists.jboss.org
Mon Mar 31 16:16:04 EDT 2008


    [ http://jira.jboss.com/jira/browse/JBSEAM-2803?page=comments#action_12406014 ] 
            
Indrek Altpere commented on JBSEAM-2803:
----------------------------------------

We use pojos because of deployment to non ejb compliant weblogic appserver.

At http://www.infoq.com/articles/jboss-seam it states:

The @PersistenceContext injection no longer works in POJOs. In order to obtain an EntityManager in a Seam POJO, you have to initialize the EntityManager in Seam configuration file and then use the Seam @In annotation to inject it into the POJO.

In event scope, everything else worked fined except the usage of em in conversation scope after session scope activity.
And that fix for entityManager=null; after the closing fixed that part too.

Reason for event scope is optimization for less memory usage, using em in event scope allows memory to be gc'able quite soon after request and memory consumption does not buld up so much as when in conversation scope.

Is there any specific reason for not using em in event scope or some tips/tricks/known facks on how to impove em performance and making the memory GC'able sooner ?

> In specific cases, a closed entitymanager is injected by seam, resulting in illegalstateexceptions
> --------------------------------------------------------------------------------------------------
>
>                 Key: JBSEAM-2803
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-2803
>             Project: JBoss Seam
>          Issue Type: Bug
>          Components: Framework
>    Affects Versions: 2.1.0.A1
>         Environment: Glassfish v2ur1, Icefaces 1.7.0
>            Reporter: Indrek Altpere
>   Original Estimate: 4 hours
>  Remaining Estimate: 4 hours
>
> EntityManager is put to event Scope for better memory usage and GC.
> Class that tries to use the entitymanager is itself in conversation scope, and this specific behavior occurs after icefaces file upload.
> Injected em is closed and throws IllegalStateException for every function used (as it should when it's closed).
> I dug around the persistence namespace/package and found once place that could explain it.
> src/main/org/jboss/seam/persistence/ManagedPersistenceContext.java
> line 225 to 229
>       if (entityManager!=null)
>       {
>          entityManager.close();
>       }
> As seen, entityManager is closed but since getEntityManager() function only creates new entitymanager when entityMAnager is null and does not check for entityManager being closed, the closed entitymanager gets passed around.
> I added entityManager = null; after the entityManager.close(); line so that the getEntityManager() would correctly return new entitymanager after old one was closed and recompiled the latest sources.
> It seemed to fix this issue, no more errors, em injected to the conversation scope class is not closed one anymore :)
> There may be some other things related to this like JBSEAM-2666 but I'm not entirely sure about it.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list