1 Reply Latest reply on Dec 21, 2008 9:07 AM by Yiu Wing Tsang

    do not auto commit after method is returned

    Yiu Wing Tsang Newbie

      jboss 4.2
      ejb 3
      stateless session bean
      transaction = container managed, REQUIRED
      using jboss-spring interceptor to inject dependencies (e.g. the hibernate dao) to the session bean

      we are using ejb 3 stateless session bean to wrap the hibernate codes to do database CRUD
      (just simple hibernate, not ejb3 entity)

      it happens that

      no "COMMIT" happens after the session bean is returned successfully, i.e. the hibernate update is not flushed to db;

      but the changes can be updated to db if we call "hibernate session's flush" explicitly


      we want to use container managed transaction, so any hint to my problem?

      thanks

        • 1. Re: do not auto commit after method is returned
          Yiu Wing Tsang Newbie

          persistence.xml:

          <persistence xmlns="http://java.sun.com/xml/ns/persistence"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
           version="1.0">
           <persistence-unit name="angelfish">
           <jta-data-source>java:/OracleDS</jta-data-source>
           <properties>
           <property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>
           </properties>
           </persistence-unit>
          </persistence>
          


          hibernate.cfg.xml:
          <hibernate-configuration>
           <session-factory>
           <property name="connection.datasource">java:/OracleDS</property>
           <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
           <property name="show_sql">true</property>
           <property name="format_sql">true</property>
           </session-factory>
          </hibernate-configuration>
          


          class annotations of session bean
          @Clustered
          @Stateless
          @Interceptors(SpringLifecycleInterceptor.class)
          @Remote(XXX.class)
          @PermitAll
          @TransactionAttribute(TransactionAttributeType.REQUIRED)
          @TransactionManagement(TransactionManagementType.CONTAINER)
          


          i have tried to add the @TransactionAttribute to the method, it also does not work



          in fact, i also tried to implement SessionSynchronization
          but for the all three callback methods
          afterBegin
          afterCompletion
          beforeCompletion
          

          i have added debug print outs, it seems that the SessionSynchornization methods are not called

          but i am quite sure a transaction should be opened, otherwise, i will receive complain from hibernate ,
          the situation now is, no exception occurs in executing the session bean method, every thing looks fine except that the updated data is not committed/flushed to db, unless we call hibernate session's flush explicitly