These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: JTA/JOTM/Hibernate Problem
PostPosted: Mon Feb 06, 2006 12:12 am 
Newbie

Joined: Sun Feb 05, 2006 11:46 pm
Posts: 13
I am using Hibernate and JOTM in a stand alone application. I have ran into a number of issues which have been resolved by reading some of the threads on this forum.

I have one remaining problem. When I call session.flush the database is updated even if I call rollback on my UserTransaction object. I have tested this in a Weblogic 8.1 server and it correctly rolls it back so I assume I havent correctly configured JOTM to manage the connections correctly.

I tried using the XA data source that comes with Informix but that didnt work. I then tried using XAPool's StandardXADataSource and set the transaction manager on it but that also didnt work.

Can anyone help me out to get the JTA working in my app.

Hibernate version: 3.0.5]

[b]Mapping documents:
N/A, its a transaction issue

<session-factory>

<property name="dialect">org.hibernate.dialect.InformixDialect</property>
<property name="hibernate.connection.datasource">jdbc/dataSource</property>

<property name="hibernate.connection.provider_class">XADataSourceConnectionProvider</property>

<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>

<property name="hibernate.current_session_context_class">jta</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JOTMTransactionManagerLookup</property>

<property name="hibernate.show_sql">true</property>
<property name="hibernate.debug">true</property>

<mapping resource="com/nickygray/shopping/vo/Products.hbm.xml" />

</session-factory>

[b]Code :

Code:
    private static void testHibernateTransactionUsingXA() throws Exception {

        System.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
        Context ictx = new InitialContext();
     
        TMService jotm = new Jotm(true, false);
             
        InformixXADataSource ifxds = new InformixXADataSource();
        ifxds.setDriverName("com.informix.jdbc.IfxDriver");
        ifxds.setUrl("jdbc:informix-sqli://lasun091:1550/lasptdb:INFORMIXSERVER=dev_lime");
        ifxds.setUser("lasptwla");
        ifxds.setPassword("spam1test");
        ifxds.setTransactionManager(jotm.getTransactionManager());
               
        ictx.rebind(USER_TRANSACTION_JNDI_NAME, jotm.getUserTransaction());
        ictx.rebind("jdbc/dataSource", ifxds);

        // jotm resets this property, so set it back to what we want
        System.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
       
        // get a transaction
        UserTransaction ut = jotm.getUserTransaction();
        // start a new transaction
        ut.begin();

        //////////////////////////////////////////
        // session 1
        Configuration cfg = new Configuration();
        File file = new File( "D:/DevEnvironments/smis/workspace/shopping/src/hibernate.cfg.xml" );
        SessionFactory sf = cfg.configure( file ).buildSessionFactory();
        Session session = sf.getCurrentSession();
        System.out.println("session 1 connection: " + session.connection());
       
        Products product2 = new Products();
        product2.setId(new Integer((int) new Date().getTime()));
        product2.setName("session 1");
        product2.setAmount(new Integer(23));
        product2.setPrice(34.3);
        session.save(product2);
        session.flush();

        //////////////////////////////////////////

        session.disconnect();
        session.reconnect();

        //////////////////////////////////////////
        // session 2 with diff db connection
       
        Session session2 = sf.getCurrentSession();
        System.out.println("session 2 connection: " + session2.connection());       
       
        Products product3 = new Products();
        product3.setId(new Integer((int) new Date().getTime()));
        product3.setName("session 2");
        product3.setAmount(new Integer(23));
        product3.setPrice(34.3);
        session2.save(product3);

        //////////////////////////////////////////

        // rollback/commit transaction
        System.out.println("commiting/rollback database");
        ut.rollback();
       
        // clean up
        System.out.println("closing jotm");
        jotm.stop();
    }

Full stack trace of any exception that occurs:
N/A

Name and version of the database you are using:
Informix 9.2


The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
2006-02-06 13:45:31,009 Environment INFO - Hibernate 3.0.5
2006-02-06 13:45:31,009 Environment INFO - hibernate.properties not found
2006-02-06 13:45:31,009 Environment INFO - using CGLIB reflection optimizer
2006-02-06 13:45:31,009 Environment INFO - using JDK 1.4 java.sql.Timestamp handling
2006-02-06 13:45:31,087 Configuration INFO - configuring from file: hibernate.cfg.xml
2006-02-06 13:45:31,431 Configuration INFO - Mapping resource: com/nickygray/shopping/vo/Products.hbm.xml
2006-02-06 13:45:31,556 HbmBinder INFO - Mapping class: com.nickygray.shopping.vo.Products -> products
2006-02-06 13:45:31,571 Configuration INFO - Configured SessionFactory: null
2006-02-06 13:45:31,587 Configuration INFO - processing extends queue
2006-02-06 13:45:31,587 Configuration INFO - processing collection mappings
2006-02-06 13:45:31,587 Configuration INFO - processing association property references
2006-02-06 13:45:31,587 Configuration INFO - processing foreign key constraints
2006-02-06 13:45:31,650 ConnectionProviderFactory INFO - Initializing connection provider: XADataSourceConnectionProvider
2006-02-06 13:45:31,681 NamingHelper INFO - JNDI InitialContext properties:{}
2006-02-06 13:45:31,681 XADataSourceConnectionProvider INFO - Using datasource: jdbc/dataSource
getting connection
2006-02-06 13:45:32,071 SettingsFactory INFO - RDBMS: Informix Dynamic Server, version: 9.40.UC3
2006-02-06 13:45:32,071 SettingsFactory INFO - JDBC driver: IBM Informix JDBC Driver for IBM Informix Dynamic Server, version: 2.21.JC5
2006-02-06 13:45:32,087 Dialect INFO - Using dialect: org.hibernate.dialect.InformixDialect
2006-02-06 13:45:32,103 TransactionFactoryFactory INFO - Transaction strategy: org.hibernate.transaction.JTATransactionFactory
2006-02-06 13:45:32,118 NamingHelper INFO - JNDI InitialContext properties:{}
2006-02-06 13:45:32,118 TransactionManagerLookupFactory INFO - instantiating TransactionManagerLookup: org.hibernate.transaction.JOTMTransactionManagerLookup
2006-02-06 13:45:32,118 TransactionManagerLookupFactory INFO - instantiated TransactionManagerLookup
2006-02-06 13:45:32,118 TransactionManagerLookupFactory INFO - instantiating TransactionManagerLookup: org.hibernate.transaction.JOTMTransactionManagerLookup
2006-02-06 13:45:32,118 TransactionManagerLookupFactory INFO - instantiated TransactionManagerLookup
2006-02-06 13:45:32,118 SettingsFactory INFO - Automatic flush during beforeCompletion(): enabled
2006-02-06 13:45:32,118 SettingsFactory INFO - Automatic session close at end of transaction: enabled
2006-02-06 13:45:32,118 SettingsFactory INFO - Scrollable result sets: enabled
2006-02-06 13:45:32,118 SettingsFactory INFO - JDBC3 getGeneratedKeys(): disabled
2006-02-06 13:45:32,118 SettingsFactory INFO - Connection release mode: null
2006-02-06 13:45:32,118 SettingsFactory INFO - Default batch fetch size: 1
2006-02-06 13:45:32,118 SettingsFactory INFO - Generate SQL with comments: disabled
2006-02-06 13:45:32,118 SettingsFactory INFO - Order SQL updates by primary key: disabled
2006-02-06 13:45:32,118 SettingsFactory INFO - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-02-06 13:45:32,134 ASTQueryTranslatorFactory INFO - Using ASTQueryTranslatorFactory
2006-02-06 13:45:32,134 SettingsFactory INFO - Query language substitutions: {}
2006-02-06 13:45:32,134 SettingsFactory INFO - Second-level cache: enabled
2006-02-06 13:45:32,134 SettingsFactory INFO - Query cache: disabled
2006-02-06 13:45:32,134 SettingsFactory INFO - Cache provider: org.hibernate.cache.EhCacheProvider
2006-02-06 13:45:32,134 SettingsFactory INFO - Optimize cache for minimal puts: disabled
2006-02-06 13:45:32,134 SettingsFactory INFO - Structured second-level cache entries: disabled
2006-02-06 13:45:32,150 SettingsFactory INFO - Echoing all SQL to stdout
2006-02-06 13:45:32,150 SettingsFactory INFO - Statistics: disabled
2006-02-06 13:45:32,150 SettingsFactory INFO - Deleted entity synthetic identifier rollback: disabled
2006-02-06 13:45:32,150 SettingsFactory INFO - Default entity-mode: pojo
2006-02-06 13:45:32,290 SessionFactoryImpl INFO - building session factory
2006-02-06 13:45:32,306 Configurator WARN - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/DevEnvironments/third-party/lib/hibernate/ehcache-1.1.jar!/ehcache-failsafe.xml
2006-02-06 13:45:32,650 SessionFactoryObjectFactory INFO - Not binding factory to JNDI, no JNDI name configured
2006-02-06 13:45:32,650 SessionFactoryImpl INFO - Checking 0 named queries
getting connection
session 1 connection: StandardXAConnectionHandle:
global transaction =<false>
is really used =<false>
this autoCommit =<true>
in use size =<0>
master prepared stmt cache size =<2>
transaction =<null>
connection =<com.informix.jdbc.IfxSqliConnect@ec6b00>

Hibernate: insert into products (NAME, PRICE, AMOUNT, ID) values (?, ?, ?, ?)
2006-02-06 13:45:32,962 JDBCExceptionReporter WARN - SQL Warning: 0, SQLState: 01I01
2006-02-06 13:45:32,962 JDBCExceptionReporter WARN - Database has transactions
2006-02-06 13:45:32,962 JDBCExceptionReporter WARN - SQL Warning: 0, SQLState: 01I04
2006-02-06 13:45:32,962 JDBCExceptionReporter WARN - Database selected
getting connection
session 2 connection: StandardXAConnectionHandle:
global transaction =<false>
is really used =<false>
this autoCommit =<true>
in use size =<0>
master prepared stmt cache size =<3>
transaction =<null>
connection =<com.informix.jdbc.IfxSqliConnect@79e304>

commiting/rollback database
2006-02-06 13:45:33,009 JDBCExceptionReporter WARN - SQL Warning: 0, SQLState: 01I01
2006-02-06 13:45:33,009 JDBCExceptionReporter WARN - Database has transactions
2006-02-06 13:45:33,009 JDBCExceptionReporter WARN - SQL Warning: 0, SQLState: 01I04
2006-02-06 13:45:33,009 JDBCExceptionReporter WARN - Database selected
closing jotm

Code:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 1:16 am 
Newbie

Joined: Sun Feb 05, 2006 11:46 pm
Posts: 13
I have also noticed that if I close the first session, dont close the second connection and then commit the data saved on the first session isnt written to the database. Is this expected behaviour?

If I never call close or flush it all works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 2:27 am 
Newbie

Joined: Sun Feb 05, 2006 11:46 pm
Posts: 13
Can anyone help please?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.