-->
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.  [ 2 posts ] 
Author Message
 Post subject: CMT leaving data behind on rollback.
PostPosted: Thu Aug 11, 2005 3:49 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:56 am
Posts: 35
I'm trying to force hibernate to rollback a transaction, as a test. I've included the code for doing so below. My problem is, even if I call ctx.setRollBackOnly() a record for the object still exists in the database after the method executes. I'm testing this method via a remote call to a Stateless Session Bean.

Hibernate version: 2.1.8

JBoss version: 4.0.1sp1

Mapping documents:

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="com.lg.hibernate.dbo.UserCredentials"
        table="user_credentials"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Integer"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="uid"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="uid"
            length="32"
        />

        <property
            name="userName"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="user_name"
            length="50"
            not-null="true"
            unique="true"
        />

        <property
            name="password"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="password"
            length="50"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-UserCredentials.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


sections from ejb-jar.xml

Code:
<container-transaction >
      <method >
         <ejb-name>UserFacade</ejb-name>
         <method-intf>Remote</method-intf>
         <method-name>createUser</method-name>
         <method-params>
           
          <method-param>com.lg.hibernate.dbo.UserCredentials</method-param>
         </method-params>
      </method>
      <trans-attribute>RequiresNew</trans-attribute>
   </container-transaction>

Code between sessionFactory.openSession() and session.close():

Code:
public User createUser(UserCredentials creds)
        throws DataStoreException,
        UserExistsException {
        try {
          Session sess = HibernateContext.getSession(LG_SESSION);
         
         sess.save(creds);
         
         ctx.setRollbackOnly();
         throw new EJBException("forced rollback");
      } catch (HibernateException e) {
          ctx.setRollbackOnly();
         throw new UserExistsException(e.getMessage(), e);
      }
      
      return null;
    }


Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySQL 4.0.24
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 7:03 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:56 am
Posts: 35
When you are using MySQL it helps to use a table type (InnoDB) that supports transactions.


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