glassfish
  1. glassfish
  2. GLASSFISH-15257

[Regression] Cannot unwrap EntityManager

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.1_b33
    • Fix Version/s: None
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Ubuntu Linux 10.04, JDK 1.6.0_22

      Description

      Working with Hibernate 3.5.3-Final as persistence provider, I'm trying to use the connection underlying the current EntityManager as follows:

      SessionImplementor session = em.unwrap(SessionImplementor.class);
      Connection con = session.connection();

      This works as expected on Glassfish 3.0.1.

      On 3.1-b33, I get the following exception:

      Caused by: javax.persistence.PersistenceException: Hibernate cannot unwrap interface org.hibernate.engine.SessionImplementor
      at org.hibernate.ejb.AbstractEntityManagerImpl.unwrap(AbstractEntityManagerImpl.java:982)
      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.unwrap(EntityManagerWrapper.java:1072)

      The Hibernate unwrap() implementation looks rather innocent:

      public <T> T unwrap(Class<T> clazz) {
      if ( Session.class.isAssignableFrom( clazz ) )

      { return ( T ) getSession(); }
      if ( SessionImplementor.class.isAssignableFrom( clazz ) ) { return ( T ) getSession(); }

      if ( EntityManager.class.isAssignableFrom( clazz ) )

      { return ( T ) this; }

      throw new PersistenceException( "Hibernate cannot unwrap " + clazz );
      }

      Have there been any changes in the Glassfish glue code between the container and the JPA provider? Or is this some kind of classloader issue?

      I'm using an all-in-one WAR with Hibernate and all its dependencies bundled in the WAR.

      I have been unable to deploy this WAR to GF ever since 3.1-b30, mainly for other reasons related to Weld and Jersey, which seem to be fixed now. The last known good version is 3.1-b26.

        Activity

        Hide
        Mitesh Meswani added a comment -

        This certainly seems like class loader issue. Can you put a breakpoint in unwrap() and check class loader for Session.class and SessionImplementor.class
        You are sure you do not have a version of Hibernate visible to GlassFish container (in lib or domain/lib dir)?

        Show
        Mitesh Meswani added a comment - This certainly seems like class loader issue. Can you put a breakpoint in unwrap() and check class loader for Session.class and SessionImplementor.class You are sure you do not have a version of Hibernate visible to GlassFish container (in lib or domain/lib dir)?
        Hide
        Harald Wellmann added a comment - - edited

        I used a fresh download of Glassfish 3.1b33 and an old version of my WAR including Hibernate. I did not copy any JARs to any of the Glassfish lib folders, so I'm sure that Glassfish only sees the Hibernate version from my WAR.

        I'm afraid it's not so easy setting a breakpoint as you suggested, since this WAR is an old binary snapshot of my project and I do not have a matching debugging environment currently.

        Show
        Harald Wellmann added a comment - - edited I used a fresh download of Glassfish 3.1b33 and an old version of my WAR including Hibernate. I did not copy any JARs to any of the Glassfish lib folders, so I'm sure that Glassfish only sees the Hibernate version from my WAR. I'm afraid it's not so easy setting a breakpoint as you suggested, since this WAR is an old binary snapshot of my project and I do not have a matching debugging environment currently.
        Hide
        Mitesh Meswani added a comment -

        I tried a simple war having structure as [1] and following code

        org.hibernate.engine.SessionImplementor session = em.unwrap(org.hibernate.engine.SessionImplementor.class);
        out.println("Got session as...." + session);

        This produced following without any exceptions in server.log

        Got session as....SessionImpl(PersistenceContext[entityKeys=[EntityKeyexample.entity.UserCredential#too],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])

        Closing as "Cannot reproduce". If you are still able to see the issue, please reopen with test case attached.

        [1] Structure of deployed war
        $ jar -tf build/basicwebapp.war
        META-INF/
        META-INF/MANIFEST.MF
        WEB-INF/
        WEB-INF/web.xml
        index.jsp
        login.html
        query.html
        registration.html
        WEB-INF/lib/
        WEB-INF/lib/antlr-2.7.6.jar
        WEB-INF/lib/commons-collections-3.1.jar
        WEB-INF/lib/dom4j-1.6.1.jar
        WEB-INF/lib/hibernate3.jar
        WEB-INF/lib/javassist-3.12.0.GA.jar
        WEB-INF/lib/slf4j-api-1.6.1.jar
        WEB-INF/lib/slf4j-jdk14-1.6.1.jar
        WEB-INF/classes/
        WEB-INF/classes/META-INF/
        WEB-INF/classes/example/
        WEB-INF/classes/example/entity/
        WEB-INF/classes/example/servlet/
        WEB-INF/classes/META-INF/persistence.xml
        WEB-INF/classes/example/entity/UserCredential.class
        WEB-INF/classes/example/servlet/QueryServlet.class
        WEB-INF/classes/example/servlet/RegistrationServlet.class
        WEB-INF/classes/example/servlet/UpdateServlet.class

        Show
        Mitesh Meswani added a comment - I tried a simple war having structure as [1] and following code org.hibernate.engine.SessionImplementor session = em.unwrap(org.hibernate.engine.SessionImplementor.class); out.println("Got session as...." + session); This produced following without any exceptions in server.log Got session as....SessionImpl(PersistenceContext[entityKeys=[EntityKey example.entity.UserCredential#too ],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]]) Closing as "Cannot reproduce". If you are still able to see the issue, please reopen with test case attached. [1] Structure of deployed war $ jar -tf build/basicwebapp.war META-INF/ META-INF/MANIFEST.MF WEB-INF/ WEB-INF/web.xml index.jsp login.html query.html registration.html WEB-INF/lib/ WEB-INF/lib/antlr-2.7.6.jar WEB-INF/lib/commons-collections-3.1.jar WEB-INF/lib/dom4j-1.6.1.jar WEB-INF/lib/hibernate3.jar WEB-INF/lib/javassist-3.12.0.GA.jar WEB-INF/lib/slf4j-api-1.6.1.jar WEB-INF/lib/slf4j-jdk14-1.6.1.jar WEB-INF/classes/ WEB-INF/classes/META-INF/ WEB-INF/classes/example/ WEB-INF/classes/example/entity/ WEB-INF/classes/example/servlet/ WEB-INF/classes/META-INF/persistence.xml WEB-INF/classes/example/entity/UserCredential.class WEB-INF/classes/example/servlet/QueryServlet.class WEB-INF/classes/example/servlet/RegistrationServlet.class WEB-INF/classes/example/servlet/UpdateServlet.class
        Hide
        Harald Wellmann added a comment -

        Strange, I can't reproduce the exception either. But I do have the logfile to prove I wasn't drunk Anyway, thanks for checking!

        Show
        Harald Wellmann added a comment - Strange, I can't reproduce the exception either. But I do have the logfile to prove I wasn't drunk Anyway, thanks for checking!

          People

          • Assignee:
            Mitesh Meswani
            Reporter:
            Harald Wellmann
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: