4 Replies Latest reply on Apr 19, 2012 5:38 PM by tomsmith

    Hibernate sessionfactory jndi bindingc

    tomsmith

      Hello,

       

      I got a problem porting a application from Jboss6 to Jboss7 (7.1.1 final)

       

      Application works perfectly, the main ejb get's a hibernate session per request through

       

      @PersistenceContext(unitName="testResellerService")

      private Session sqlSession;

       

       

      but when jboss starts the persistenceunit automatically, it does not try to bind the sessionfactory to jndi (like Jboss6)

       

      <property name="session_factory_name">java:jboss/testSessionFactory</property>

       

      is useless...

       

       

      I have additional asynchronous threads with Quartz scheduler launching.
      In Jboss6 they looked up the sessionfactory through JNDI

       

      Now in Jboss7 I am unable to get the sessionfactory.
      There is no error, Jboss7 is not trying to bind Hibernate sessionfactory in JNDI.

       

      Any help? How to get the sessionfactory (with envers etc.) in Quartz Jobs?

       

       

      Thanks!

      Tom

        • 1. Re: Hibernate sessionfactory jndi bindingc
          smarlow

          Are you setting the "hibernate.session_factory_name" property?  Above you said "session_factory_name".

          • 2. Re: Hibernate sessionfactory jndi bindingc
            smarlow

            You shouldn't have to set it but there is also a new property "hibernate.session_factory_name_is_jndi" that you could set to true if you like.

             

            Also might not hurt to enable TRACE logging for org.hibernate and org.jboss.as.jpa (see link here for instructions.)

            1 of 1 people found this helpful
            • 3. Re: Hibernate sessionfactory jndi bindingc
              tomsmith

              Scott, thank you! This bugged me a whole day. The property worked like a charme on Jboss6... "hibernate.session_factory_name" is the right name!

              • 4. Re: Hibernate sessionfactory jndi bindingc
                tomsmith

                Okay, there is another minor problem raised. I found some entries in google but none of them were actually in the situation of jboss7/hibernate4. Mentioned solutions do not work.

                 

                org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [java:comp/UserTransaction]

                 

                I know that java:comp/UserTransaction is only visible for container created threads of jee, so not for my quartz threads.

                 

                The right thing for me seems to be java:jboss/UserTransaction

                 

                 

                none of the mentioned config options worked for me. There is always java:comp/UserTransaction looked up from hibernate which fails in quartz threads.

                 

                I tried:

                 

                        <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>

                        <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>

                        <property name="jta.UserTransaction" value="java:jboss/UserTransaction"/>

                 

                jta.UserTransaction property is listed in hibernate docs.

                 

                 

                I replaced the last one already with following possiblities, of which none had an effect:

                 

                <property name="hibernate.jta.UserTransaction" value="java:jboss/UserTransaction"/>

                <property name="jta.UserTransaction" value="java:jboss/UserTransaction"/>

                <property name="jta.UserTransactionName" value="java:jboss/UserTransaction"/>

                <property name="hibernate.jta.UserTransactionName" value="java:jboss/UserTransaction"/>

                 

                 

                jboss says at startup:

                 

                23:31:19,113 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-3) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory

                 

                transactions work in the normal application!

                 

                 

                Thanks again!