3 Replies Latest reply on Feb 27, 2007 6:26 PM by Gavin King

    Using the JPA delegate

    eirirlar Newbie

      Hi, I wonder if I'm the only one who's encountered this when trying to use the JPA delegate when Hibernate is the underlying persitence provider.

      Look at chapter 8.4 in the doc. It says:

      @In EntityManager entityManager;
      
      @Create
      public void init() {
       ( (Session) entityManager.getDelegate() ).enableFilter("currentVersions");
      }


      From my experience, entityManager.getDelegate() returns a org.hibernate.ejb.EntityManagerImpl, not a org.hibernate.Session. So the code in the example should be replaced by something like this:

      @In EntityManager entityManager;
      
      @Create
      public void init() {
       ( (Session) ((HibernateEntityManager)em.getDelegate()).getSession()).enableFilter("currentVersions");
      }


        • 1. Re: Using the JPA delegate
          Gavin King Master

          This was a bug in older versions of HEM. It *should* work right in JBoss 4.0.5....

          • 2. Re: Using the JPA delegate
            eirirlar Newbie

            It seems that the entityManager.getDelegate() returns either a SessionImpl or a EntityManagerImpl, depending on wether or not you have the following set up in your components.xml:

            <core:managed-persistence-context name="bookingDatabase"
             auto-create="true"
            persistence-unit-jndi-name="java:/EntityManagerFactories/bookingData"/>


            and persistence.xml:

            <property name="jboss.entity.manager.factory.jndi.name"
             value="java:/EntityManagerFactories/bookingData"/>


            That is - if this is set up, SessionImpl is returned. Otherwise EntitiyManagerImpl is returned.

            I can't really find a logical explanation for this, but it's not a problem as long as I know about it.

            • 3. Re: Using the JPA delegate
              Gavin King Master

              Perhaps it was an EJB3 container bug - in which case I'm sure the fix will be in JBoss 4.2.