1 Reply Latest reply on Sep 25, 2006 7:29 PM by Jason Holmes

    JBoss is not beginning transaction

    Jason Holmes Newbie

      Hi,
      I'm using JBoss 4.0.4-GA with Hibernate 3.2CR4 and EJB 2.1. Hibernate is complaining that "load is not valid without active transaction" This comes form the TransactionManager that is checking to see if the Transaction is active. The transaction exists, it just has not begun.

      I have a stateless session bean using CMT that looks like this ...

      /**
       * @ejb.bean name="GeoFeatureServer"
       * jndi-name="com.free2be.framework.gis.feature.GeoFeatureServerHome"
       * type="Stateless" view-type="remote"
       * @ejb.transaction type="Required"
       */
      public abstract class GeoFeatureServerBean implements SessionBean {
       /**
       * @ejb.interface-method
       */
       public GeoFeature findGeoFeature(GeoFeaturePk geoFeaturePk) throws NoSuchElementException {
       GeoFeature value = (GeoFeature) cache.getByKey(geoFeaturePk);
       if (value == null) {
       getLogger().debug(geoFeaturePk + " not cached...loading");
       value = getGeoFeatureDao().findById(geoFeaturePk, false);
       cache.addToCache(value);
       }
       return value;
       }
      }
      


      The DAO code looks like this ...
       @SuppressWarnings("unchecked")
       public V findById(long id, boolean lock) {
       V entity;
       try {
       Session session = getSession();
      // Transaction tx = session.beginTransaction();
       if (lock)
       entity = (V) session.load(getPersistentClass(), id, LockMode.UPGRADE);
       else
       entity = (V) session.load(getPersistentClass(), id);
       } catch (HibernateException e) {
       throw new NoSuchElementException(e.getMessage());
       }
      
       return entity;
       }
      


      If I un-comment the session.beginTransaction(), the exception won't be thrown. However, we're using CMT, so I shouldn't have to do that. In fact, I shouldn't be allowed to do that. Touching the transaction should throw an exception AFAIK.

      My hibernate.properties file ...
      hibernate.dialect=org.hibernate.dialect.MySQLDialect
      hibernate.connection.driver_class=com.mysql.jdbc.Driver
      hibernate.connection.url=jdbc:mysql://integration:3306/mbgeo
      hibernate.connection.username=xxxx
      hibernate.connection.password=xxxx
      
      #don't use hibernate's pooling! http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html
      hibernate.c3p0.min_size=5
      hibernate.c3p0.max_size=20
      hibernate.c3p0.timeout=1800
      hibernate.c3p0.max_statements=50
      
      hibernate.session_factory_name=hibernate/session_factory
      jta.UserTransaction=UserTransaction
      
      #hibernate.current_session_context_class=jta #can leave unset, default is jta
      hibernate.transaction.factory_class=org.hibernate.transaction.CMTTransactionFactory
      hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
      hibernate.transaction.flush_before_completion=true
      
      hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
      hibernate.show_sql=true
      hibernate.format_sql=true
      hibernate.generate_statistics=true
      
      hibernate.bytecode.use_reflection_optimizer=false
      hibernate.bytecode.provider=javassist


      Anybody have any ideas as to what I'm doing wrong?

      -Jason