-->
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.  [ 5 posts ] 
Author Message
 Post subject: JTA Transaction not updating InnoDB tables
PostPosted: Mon Sep 04, 2006 12:35 am 
Newbie

Joined: Thu Aug 03, 2006 6:54 pm
Posts: 16
I recenlty switched over from MyISAM to InnoDB tables in my MySQL 5.0.20 database to ensure transactions rolled back if they were not valid. Also, I am using Hibernate 3.1.

Performing a simple JDBC transaction, the following code works correctly i.e. my InnoDB table is updated correctly:

Code:
Customer ctmr = new Customer("John", "Doe");
ctmr.setcid(1);  //Set customer ID

Fintrans fts = new Fintrans();
fts.setAmountWillingToPay(12000.05);
fts.setCustomer(ctmr);
fts.setDatetime("06/22/2006");
fts.setGrandTotalAccrued(3213.20);
fts.setGrandTotalPaid(13651.10);
fts.setReason("No reason given");

Session session = factory.openSession();
Transaction tx = null;
       
try{
    tx = session.beginTransaction();
    session.save(fts);
    tx.commit();
}catch(Exception e){
    if (tx!=null)
        tx.rollback();
    throw e;
}


However, when I try and perform the task using JTA's UserTransaction my InnoDB table is not updated:

Code:
Customer ctmr = new Customer("John", "Doe");
ctmr.setcid(1);  //Set customer ID

Fintrans fts = new Fintrans();
fts.setAmountWillingToPay(12000.05);
fts.setCustomer(ctmr);
fts.setDatetime("06/22/2006");
fts.setGrandTotalAccrued(3213.20);
fts.setGrandTotalPaid(13651.10);
fts.setReason("No reason given");

UserTransaction tx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
       
try{
    tx.begin();
    factory.getCurrentSession().save(fts);
    tx.commit();
}catch(Exception e){
    if (tx!=null)
        tx.rollback();
    throw e;
}


If I perform the above (UserTransaction) code using MyISAM tables it works perfectly. Below is my Hibernate.cfg.xml:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
       "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
      <property name="connection.url">zzzzzzz</property>
      <property name="connection.username">zzzzzz</property>
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
      <property name="connection.password">zzzzz</property>
      <property name="connection.pool_size">2</property>

      <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>

       <property name="current_session_context_class">org.hibernate.context.JTASessionContext</property>

   
      <property name="transaction.manager_lookup_class">org.hibernate.transaction.SunONETransactionManagerLookup</property>

      <property name="jta.UserTransaction">java:comp/UserTransaction</property>

       <!-- this will show us all sql statements -->
       <property name="hibernate.show_sql">true</property>
   
       <!-- this will create the database tables for us -->
       <property name="hibernate.hbm2ddl.auto">update</property>
           
   </session-factory>
</hibernate-configuration>


I think the problem could be something to do with the following line of code in my Hibernate.cfg.xml:

Code:
  <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>


This is because, when I was originally trying to perform my JDBC transaction (on the InnoDB tables) with this line of code I was getting the same problem. I eventually figured out that by removing this from my Hibernate.cfg.xml the update worked fine. However, I think I need this in order to perform a UserTransaction.

If anyone can provide help on the matter that would be greatly appreciated.

Outlaw.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 04, 2006 10:01 pm 
Newbie

Joined: Thu Aug 03, 2006 6:54 pm
Posts: 16
It seems as though my problem may lie within Hibernate.cfg.xml. The connection is not flushed which would indicate a configuration error.

If anyone could provide help on the matter that would be appreciated.

Outlaw.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 7:04 pm 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

I have the same problem as you where my records are not updated.
Have you found out the cause? If so, really appreciate if you can share with me.

Thanks in advance.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 7:38 pm 
Newbie

Joined: Thu Aug 03, 2006 6:54 pm
Posts: 16
I have made numerous posts on this matter but noone seems to have an answer for me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 11:14 pm 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
After session.save(), include session.flush() as well and see if it works for you?

Mine can work after include session.flush().

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.