Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I work in a project that uses JavaEE. I work with Glassfish servers version 3. I'm frequently having a problem (not always) in my singleton EJB's that use an EntityManager instance. A lot of times, I get this error:

[timestamp] [http-thread-pool-8080(49)] ERROR com.sun.xml.ws.server.sei.TieHandler.serializeResponse Attempting to execute an operation on a closed EntityManager.
java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
 at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen(EntityManagerImpl.java:1662) ~[org.eclipse.persistence.jpa.jar:2.3.4.v20130626-0ab9c4c]
 at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:643) ~[org.eclipse.persistence.jpa.jar:2.3.4.v20130626-0ab9c4c]
 at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:532) ~[org.eclipse.persistence.jpa.jar:2.3.4.v20130626-0ab9c4c]
 at com.sun.enterprise.container.common.impl.EntityManagerWrapper.find(EntityManagerWrapper.java:320) ~[container-common.jar:3.1.2.1]


The log goes on, but I just showed the top of it. The next line of the log was the call to an WebService deployed in the same server. And when this error happens, it is always originated by a call to a WebService deployed in the same server that performs a find in the database using the method 'find' from the entityManager instance.

The entity manager is being injected outside of the bean in the @PostConstruct of a @WebService annotated class, using the line '(EntityManager)new InitialContext().lookup("java:comp/env/persistence/etc");' This is the class that receives all the incoming requests and decides which bean should be called, based on request.

Right after receiving a request, this class calls the respective singleton bean, based on the request, passing the injected EntityManager to the respective bean.

I understand that the EntityManager is closed when I try to perform the operation and that is indeed the problem. However, I thought this opening and closing of the EntityManager was managed automatically. Apparently it doesn't work that way. I'm not closing the EntityManager directly anywhere in the code either.

I'm not seeing any reasonable solution to approach this problem. All I find in online resources is that it may be a Glassfish bug and restart the server generally works. Nothing concrete to solve the problem.

Some of the information present in the PersistenceUnit configured in the persistence.xml file I'm using is presented below.

<persistence-unit> name="XXX" transaction-type="JTA"
<provider>org.eclipse.persistence.jpa.PersistenceProvider></provider>
<jta-data-source>jdbc/YYY</jta-data-source>
<properties>
            <property name="eclipselink.target-database" value="Oracle"/>
            <property name="eclipselink.cache.shared.default" value="false"/>
            <property name="eclipselink.cache.size.default" value="0"/>
            <property name="eclipselink.cache.type.default" value="None"/>
            <property name="eclipselink.weaving.internal" value="false"/>
            <property name="toplink.target-database" value="Oracle"/>
            <property name="eclipselink.session.customizer"                       
            value="aaa.bbb.ccc.IsolateEmbeddablesCustomizer"/>
 </properties>
 <exclude-unlisted-classes>true</exclude-unlisted-classes>
 </persistence-unit>


Do you have any idea on how to solve this problem or what am I doing wrong?

Thank you.

What I have tried:

-Restart the server (works temporarily)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900