-->
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.  [ 1 post ] 
Author Message
 Post subject: Testing JTA Transaction Rollback
PostPosted: Sun Aug 27, 2006 9:19 pm 
Newbie

Joined: Thu Aug 03, 2006 6:54 pm
Posts: 16
I have the following code to test whether a JTA Transaction really can rollback:

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");

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


I have two tables on the same database - customer and fintrans. The fintrans table has a foreign key to the customer table (cid). The customer table is empty, so when I run the above code it should rollback because cid of value 1 which I am entering into the fintrans table does not exist in the customer table. However, this is not the case. Instead I am getting the following exception and the entry is still being made in the fintrans table:

Code:
org.hibernate.TransactionException: JTA commit failed:
   org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:153)
   springapp2.controllers.OutputController.handleRequest(OutputController.java:136)
   org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:717)
   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:658)
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:392)
   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:347)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
   com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
   com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
   org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
   com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
   com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
   com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
   com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
   com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
   com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
   com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)


I dont think there is any problems with my configuration file:
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.MySQLMyISAMDialect</property>
      <property name="connection.password">zzzzz</property>
      <property name="connection.pool_size">10</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>


Is this what is supposed to happen? I thought rollback should not allow the entry to be made into the database table.

Any help in the matter would be greatly appreciated.

Outlaw.


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

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.