0 Replies Latest reply on Apr 22, 2008 6:48 PM by Robert Diaz

    Hibernate Session problems

    Robert Diaz Newbie

      Hi all,


      I know that I have posted before on this subject, but the problem is still here. I am unable to get seam to generate a Session on its on. Without that, things like the HibernateEntityQuery object will not work at all. I just get a message saying that my session is null.


      I found a slight work around that was more of a hack then anything really useful. I used Hibernate and created my own SessionFactory and Session and that worked perfectly, except that the built in objects could not use my Session.


      The hibernate.cfg.xml that I used is the exact same as the one I tried to use when I was attempting at the seam managed hibernate session, so I know that it works. I just need to figure out why seam isn't creating my Session object. Seam is creating the HibernateSessionFactory and the ManagedHibernateSession, and I can get access to those, but when I do, I run into another problem...


      This new problem is kinda weird. I can call the


      hibernateSessionFactory.getSessionFactory().getCurrentSession()
      



      method and I get back an open session no problem. But, when I attempt to make any kind of database calls and a commit, it throws an error saying that I can't commit during a managed transaction. This is all that I am doing:


      ArrayList l = new ArrayList();
      
      Session s = factoryForTheSessions.getSessionFactory().getCurrentSession();
      
      s.beginTransaction();
      
      OrganizationT org = (OrganizationT) s.createQuery("select org from OrganizationT org where name = :n").setString("n", x).uniqueResult();
      
      List<HostedBy> h = (List<HostedBy>) s.createQuery("select h from HostedBy h where organization_id = :id").setString("id", org.getId()).list();
      
      for (HostedBy host : h) {
           l.addAll(s.createQuery("select event from EventT event where id = :id").setString("id", host.getId().getEventId()).list());
      }
      
      s.getTransaction().commit();
      



      And when it gets to the commit(), it throws an error. I have turned off the hibernate auto commit, so that has nothing to do with this. There is some other configuration setting that I must not know that is key in getting this to work.


      Any help would be most appreciated.


      Thanks,
      Robert


      Here are my hibernate.cfg.xml and my components.xml in case they help anyone.


      <hibernate-configuration>
          <session-factory name="java:/registrationDatabaseSessionFactory">
              <property name="connection.datasource">java:/testDatasource</property>
              
              <property name="show_sql">false</property>
              <property name="hibernate.connection.autocommit">false</property>
              <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
              <property name="transaction.flush_before_completion">false</property>
              <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
              <property name="hibernate.connection.pool_size">1</property>
              <property name="current_session_context_class">thread</property>
              
              mappings....
          </session-factory>
      </hibernate-configuration>
      



      <transaction:ejb-transaction />
          
      <persistence:hibernate-session-factory name="factoryForTheSessions"/>
          
      <persistence:managed-hibernate-session name="registrationDatabase" auto-create="true" session-factory="#{factoryForTheSessions}"/>
          
      <transaction:hibernate-transaction session="#{registrationDatabase}"/>