5 Replies Latest reply on May 23, 2005 1:03 PM by luca.mandorlo


    Shawn Garbett Newbie

      When writing an EJB that uses Hibernate I wrote the following:

      public class SomeEJB implements SomeEJBLocal, SomeEJBRemote
       private static final String jndiName="java:hibernate/TestSessionFactory";
       public void doSomeHibernate()
       Session session = HibernateContext.getSession(jndiName);

      I cringe at the thought that if naming ever changed one would have to update all of these strings referenced. One could put the strings in a properties file, or a single file class in that project. If it's mispelled it also doesn't get checked at compile time. The code of EJB usage looks so much neater:

       InitialContext ctx = new InitialContext();
       SomeEJB service=(SomeEJB)ctx.lookup(SomeEJB.class.getName());

      Is there someway to do something like this for Hibernate in JBoss so that it's a compile time check?

        • 1. Re: getSession
          beyarecords Novice

          on a slightly different note, I saw an earlier post of yours where you changed the hbm.xml files DTD from 2 to 3. Can you please tell me how your hibernate.har and jboss-hibernate.deplayer is setup as I can't get my hibernate.har to deploy at all.

          I have changed all mapping files and class files to reflect the changes required for hibernate3 to work, but whe it comes to starting Jboss hibernate.har doesn't deploy at all. Any ideas?

          many thanks


          • 2. Re: getSession
            Shawn Garbett Newbie

            There are two other issues bouncing around about Hibernate3. The configuration as currently packaged ends up with two different copies of the Hibernate jar files. Delete one, and put the other in in the common lib directory.

            The other issue is more complicated and involves the fact the Hibernate opens the session with no auto flush. One has to flush explicitly.

            I'll reply in full tomorrow.


            • 3. Re: getSession
              beyarecords Novice

              many thanks.


              • 4. Re: getSession
                Scott Stark Master

                Use a resource-ref to avoid hard-coded jndi names.

                • 5. Re: getSession
                  luca.mandorlo Newbie


                  "scott.stark@jboss.org" wrote:
                  Use a resource-ref to avoid hard-coded jndi names.

                  I try to use a resource-ref for accesing to java:/hibernate/SpikeSessionFactory called hibernate.

                  Deployment is ok, but SessionFactory object in null again!!!

                  this i the code:

                  InitialContext context = null;
                   context = new InitialContext();
                   SessionFactory factory = (SessionFactory)context.lookup("java:comp/env/hibernate");
                   Session hsession = factory.openSession();

                  and in ejb-jar.xml

                   <description>Timer Example session bean</description>
                   <display-name>Timer Example SessionBean</display-name>

                  in jboss.xml


                  Why the SessionFactory is null??? i'm gone crazy!!!