2 Replies Latest reply on Dec 20, 2007 9:32 AM by Reggie Zhou

    CMT doesn't rollback

    Reggie Zhou Newbie

      My application is using Jboss 4.2.1, EJB3(stateless session bean), EntityManager, Hibernate and Postgresql. it doesn't rollback.

      ds.xml

      <local-tx-datasource>
      <jndi-name>PGDS/JTA</jndi-name>
      <connection-url>jdbc:postgresql://localhost:5432/postgres</connection-url>
       <driver-class>org.postgresql.Driver</driver-class>
       <user-name>xxxxxx</user-name>
       <password>yyyyyy</password>
       <metadata>
       <type-mapping>PostgreSQL 8.0</type-mapping>
       </metadata>
       </local-tx-datasource>
      


      persistence.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="1.0" 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">
       <persistence-unit name="JTA-EJBPU" transaction-type="JTA">
       <jta-data-source>java:/PGDS/JTA</jta-data-source>
       <properties>
       <property name="hibernate.show_sql" value="true"/>
       </properties>
       </persistence-unit>
      </persistence>
      


      session bean
      @Stateless
      @LocalBinding(jndiBinding="JTA/JTALocal")
      public class JTABean implements JTALocal {
       @PersistenceContext(unitName = "JTA-EJBPU",type=PersistenceContextType.TRANSACTION)
       private EntityManager em ;
       @TransactionAttribute(TransactionAttributeType.REQUIRED)
       public void run (int i)throws Exception{
      
       try{
       School sc1 = new School("first");
       em.persist(sc1);
       if(i == 1) throw new Exception();
       School sc2 = new School("second");
       em.persist(sc2);
       }catch(Exception e){
      
       System.out.println("roll back?");
       throw e;
       }
       }
      
      }
      


      JBoss startup info
      [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
      [InjectedDataSourceConnectionProvider] Using provided datasource
      [SettingsFactory] RDBMS: PostgreSQL, version: 8.2.5
      [SettingsFactory] JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.2 JDBC4 with SSL (build 507)
      [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect
      [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
      [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      [SettingsFactory] Automatic flush during beforeCompletion(): disabled
      [SettingsFactory] Automatic session close at end of transaction: disabled
      [SettingsFactory] JDBC batch size: 15
      [SettingsFactory] JDBC batch updates for versioned data: disabled
      [SettingsFactory] Scrollable result sets: enabled
      [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
      [SettingsFactory] Connection release mode: auto
      [SettingsFactory] Default batch fetch size: 1
      [SettingsFactory] Generate SQL with comments: disabled
      [SettingsFactory] Order SQL updates by primary key: disabled
      [SettingsFactory] Order SQL inserts for batching: disabled
      [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
      [SettingsFactory] Query language substitutions: {}
      [SettingsFactory] JPA-QL strict compliance: enabled
      [SettingsFactory] Second-level cache: enabled
      [SettingsFactory] Query cache: disabled
      [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
      [SettingsFactory] Optimize cache for minimal puts: disabled
      [SettingsFactory] Cache region prefix: JTA-EAR_ear,JTA-EJB_jar,JTA-EJBPU
      [SettingsFactory] Structured second-level cache entries: disabled
      [SettingsFactory] Echoing all SQL to stdout
      [SettingsFactory] Statistics: disabled
      [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
      [SettingsFactory] Default entity-mode: pojo
      [SettingsFactory] Named query checking : enabled
      [SessionFactoryImpl] building session factory
      [SessionFactoryObjectFactory] Factory name: persistence.units:ear=JTA-EAR.ear,jar=JTA-EJB.jar,unitName=JTA-EJBPU
      [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
      [SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.units:ear=JTA-EAR.ear,jar=JTA-EJB.jar,unitName=JTA-EJBPU
      [SessionFactoryObjectFactory] InitialContext did not implement EventContext
      [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
      [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
      [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=JTA-EAR.ear,jar=JTA-EJB.jar,name=JTABean,service=EJB3 with dependencies:
      [JmxKernelAbstraction] persistence.units:ear=JTA-EAR.ear,jar=JTA-EJB.jar,unitName=JTA-EJBPU
      [EJBContainer] STARTED EJB: com.ganz.jta.ejb.JTABean ejbName: JTABean
      [EJB3Deployer] Deployed: file:/E:/jboss-4.2.1.GA/server/default/tmp/deploy/tmp18536JTA-EAR.ear-contents/JTA-EJB.jar
      [TomcatDeployer] deploy, ctxPath=/JTA-WAR, warUrl=.../tmp/deploy/tmp18536JTA-EAR.ear-contents/JTA-WAR-exp.war/
      [EARDeployer] Started J2EE application: file:/E:/jboss-4.2.1.GA/server/default/deploy/JTA-EAR.ear
      


      I have tried different configurations. in persistence.xml i changed to RESOURCE_LOCAL, non-jta--data-source. i have tried XA data source.
      the transaction just doesn't rollback. when i call run(1). it throws an exception between two persistence, but the first record has been saved into database already.

      according to the Jboss starup info, it is a CMT.
      Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory

      i tried jboss 4.2.0 4.2.1 4.2.2, same
      tried pure JDBC connection, same
      use MDB instead of Session Bean, same.

      anybody can help me, give me a clue. what am i missing?