Monday, 12 September 2011

Glassfish 3.1 Problems - "operation on a closed EntityManagerFactory"

The JavaEE course ships with a copy of Glassfish 3.0, so you can get started with your training right away. However, as we say on the course, if you'd rather use a more recent version of Glassfish, you should be ok.

Glassfish 3.1 was recently released, and whilst it should be fine, we've had a couple of reports of problems with re-deploying on this version.

When re-deploying you application, you may see the following symptoms:

  • No "JPA" engine is listed on the engines list. This can be ignored, it seems to be a bug on the admin console and JPA will work as usual.
  • However, after a redeploy (NOT an initial deploy), you may get an error, with the following reported in the log:

    java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.
As far as I can tell, this is a Glassfish admin console bug also. The deployment process should be responsible for opening and closing the EntityManagerFactory, and it looks like it isn't been properly re-opened on re-deployment.

If this happens to you, I can suggest one of the following:

a) Uninstall Glassfish 3.1 and use the version supplied with the course instead. You won't lose any functionality that is important to the course (all I can think of that is missing would be clustering, which isn't needed for the course).

OR

b) Instead of re-deploying, perform a clean deploy by undeploying and then deploying again (remembering to re-enter the Application Name). This is, however, a little tedious to do each time.

We will raise a bug report with Glassfish, in the meantime do let us know if you discover some steps that prevent the problem entirely.

14 comments:

  1. Thanks for the write-up. Can you file a bug report with a test case at http://java.net/jira/browse/GLASSFISH (or point me to an existing one you'd have already created)?

    ReplyDelete
  2. Hi, yes I'm just waiting for a gap in work to check the fine points. I'm not sure if it affects all dbs or if it's maybe our connection pool badly configured. Will get it done by the end of today.

    ReplyDelete
  3. Also, if you can try with the latest GlassFish 3.1.1 that would be great.

    ReplyDelete
  4. I've tested this now on Glassfish 3.1.1 with both a Derby and MySQL database and the problem is repeatable.

    Filed JIRA at http://java.net/jira/browse/GLASSFISH-17295 (I've noted it may be a duplicate of GLASSFISH-16897).

    I've found that this does NOT affect the autodeployment or re-deploying using the asadmin tool, so with the workaround I guess this isn't such a serious problem.

    ReplyDelete
  5. thanks Richard for the follow-up. Let's see what the engineers have to say.

    ReplyDelete
  6. Thanks for posting this.
    I'm working on my own project and have done quite a few EJB / Facelet apps and haven't had this problem. But tonight I am and your post saved me a lot of headaches.

    ReplyDelete
  7. I have the same trouble. To work arround, I disable the install of the ear before re-install, it is working. I think glassfish keep the last session with the old install, or some thing like that...

    ReplyDelete
  8. I'm getting the error with GlassFish Server Open Source Edition 3.1.2 (build 23). Poop.

    ReplyDelete
  9. Same problem here. asadmin redeploy works but from the webinterface I end up with the closed EntityManagerFactory.

    ReplyDelete
  10. According to the JIRA bug report we raised at http://java.net/jira/browse/GLASSFISH-17295, it looks like it is slated for the next release. I don't know why it didn't make 3.1.2.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Pronblem solved
    we write this in persistance.xml
    properties
    property name="eclipselink.logging.level" value="FINEST" /property
    properties

    if we write like this , problem will solved

    properties
    property name="eclipselink.logging.level" value="FINEST"/
    properties

    important thing is property closed tag must like this /

    ReplyDelete