-->
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.  [ 7 posts ] 
Author Message
 Post subject: Transaction not rolling back
PostPosted: Tue Mar 16, 2004 9:54 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
hi,

i was recently having some trouble with a many-to-many relationship and while i fixed this problem, during testing i noticed that my transactions were not being rolled back on error. here are the mapping files i was using, notice that both ends of the many-to-many relationship are set inverse="false" resulting in two inserts into the join table.

Code:
<hibernate-mapping>
    <class name="my.package.Account" table="Account">
        <id name="id" column="id" type="java.lang.Long" >
   <generator class="hilo"/>
        </id>   
        <set name="accountHolders" table="AccountGroup" lazy="true"
   inverse="false" cascade="save-update">
                <key column="account" />
                <many-to-many class="my.package.Customer"
                      column="customer" outer-join="auto" />
        </set>
    </class>
   
    <class name="my.package.Customer" table="Customer">
        <id name="id" column="id" type="java.lang.Long" >
              <generator class="hilo"/>
        </id>
        <set name="accounts" table="AccountGroup" lazy="true" 
               inverse="false" cascade="save-update" >
            <key column="customer" />
            <many-to-many class="my.package.Account"
                 column="account" outer-join="auto" />
         </set>
    </class>
</hibernate-mapping>


and here's my test code:

Code:
Session session = null;
Transaction transaction = null;

try {
    session = factory.openSession();
    transaction = session.beginTransaction();

    Customer customer = new Customer();
    Account account = new Account();
               
    account.addAccountHolder(customer);
    customer.addAccount(account);

    session.save(account);
    session.save(customer);

    transaction.commit();

} catch (HibernateException e) {
    try {
        transaction.rollback();
    } catch (HibernateException e1) {}
} finally {
    try {
        session.close();
    } catch (HibernateException e) {}
}



and here's the exception:

Code:
java.sql.BatchUpdateException: Invalid argument value,  message from server: "Duplicate entry '5308417-5275649' for key 1"
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1446)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2311)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2265)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at com.client.business.AccountTransactionTest.main(AccountTransactionTest.java:52)


so, after performing the test, receiving the exception and being told that the transaction has been rolled back, when i look in the database the account, customer and one of the attempted account-customer relationships have been commited. this shouldn't this happen, should it?

thanks, cam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 10:34 am 
Beginner
Beginner

Joined: Tue Nov 11, 2003 4:49 am
Posts: 47
Location: Florence, Italy
Which version of MySQL are you using ? Transaction mgmt for that DB is quite new.

_________________
Ciao.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 10:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Are you using InnoDB tables, as you should?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 11:03 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
i'm using mysql 3.23.58, and myisam.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 11:22 am 
Beginner
Beginner

Joined: Tue Nov 11, 2003 4:49 am
Posts: 47
Location: Florence, Italy
No transactions management for that version, AFAIK. Look at here:

http://www.mysql.com/doc/en/Table_types.html

_________________
Ciao.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 11:45 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
thanks for the info - can you tell me if there's any way of specifying the table type in schema export, or if i can upgrade all tables with one command?
thanks cam


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 12:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
See the FAQ (Misc).


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