9 Replies Latest reply on Jul 12, 2011 7:54 AM by smarlow

    Hibernate JNDI binding

    prasad.deshpande

      Hi Guys,

       

      I was trying to bind hibernate session factory to JNDI & it's giving me read-only JNDI error. After little bit of browsing through issues, I read Scott's comments in AS7-421 about "hibernate.session_factory_name". I'm facing the problem where I need to bind sessionfactory to JNDI & due to readonly JNDI, it's failing. Is there any workaround? Or do I have to wait until 7.1?

        • 1. Re: Hibernate JNDI binding
          jaikiran

          It's the server which is responsible for binding that to JNDI. Is there any specific reason why your code is trying to bind it?

          • 2. Re: Hibernate JNDI binding
            prasad.deshpande

            It's not my code which is binding it.. All I'm doing is

             

            pp.setProperty( "hibernate.session_factory_name", jndiName);

            & then

            sessionFactory = config.buildSessionFactory();

            After, config.buildSessionFactory(), it throws exception saying JNDI is readonly.

             

            To give you background, I'm setting properties programatically & then calling this buildSessionFactory(). This all is being done in a servlet. If that's piece of info is any useful to you

            • 3. Re: Hibernate JNDI binding
              jaikiran

              Okay, I now get your reference to https://issues.jboss.org/browse/AS7-421. Yeah, so it looks like this won't work in 7.0. Will have to wait for a future release.

              • 4. Re: Hibernate JNDI binding
                smarlow

                Note that AS7-421 + AS7-421 have zero votes.  Please vote for issues that are important to you.

                • 5. Re: Hibernate JNDI binding
                  prasad.deshpande

                  Any way to bind sessionfactory to JNDI... no..?? at all??

                  • 6. Re: Hibernate JNDI binding
                    jaikiran

                    You mean, if you are building the Hibernate session factory yourself? I don't think there's a way to get past this issue in such scenario. But Scott will know better.

                    • 7. Re: Hibernate JNDI binding
                      swd847

                      If you let the container build the EntityManagerFactory for you then the JNDI binding will work, is there any particular reason you need to build it yourself?

                      • 8. Re: Hibernate JNDI binding
                        prasad.deshpande

                        It's a legacy application which uses old style hibernate with setting properties programatically & binding sessionfactory to JNDI & then later retrieve sessionfactory to perform query/save on objects.

                         

                        I know that this all can be done by creating different persistent unit (apart from the one used for entity beans) cause both uses different properties. However if I have to migrate it to use JPA, then changes are large. Since this application is portable across other app servers as well like weblogic & glassfish (& also jboss 5.1) with it's current running state, it's hard for me to justify this change to my management.

                         

                        Also, as a quick test, I did try to create another persistent unit in same persistence.xml just for this part of application, but it gave me lot of problems with entity beans (I'm going to report that to Scott but I still need to know more details of the problem to even report.).

                         

                        Btw, just out of curiosity, when you say letting container build EntityManagerFactory, do you mean by defining persistent unit & may be injecting sessionfactory/session into corresponding places?

                        • 9. Re: Hibernate JNDI binding
                          smarlow

                          From discussion on (#jboss-as7) IRC yesterday, a few ideas for fixing "hibernate.session_factory_name" support were discussed and will be worked on.  One possibilty is to have a special JNDI location that is updateable (e.g. something under "java:jboss/").  Look for this as a post AS 7.0 change.

                           

                          Another alternative but less useful (IMO), would be to have the (JPA) container handle the binding on behalf of Hibernate.  This would be less than ideal, since native Hibernate (non-JPA) apps do not have an EE container available to handle this.