-->
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.  [ 10 posts ] 
Author Message
 Post subject: transtraction rollbacked but data updated?
PostPosted: Thu Jun 09, 2005 2:52 pm 
Newbie

Joined: Thu Jun 09, 2005 2:41 pm
Posts: 6
Hi Guys,

I tried to do some db operations( load, delete and update) in one transaction, after some steps I throw some exception and let the transaction rollback, but the db can not return to the state before I begin transaction, there are some data has been updated.

does any body know what's the problem it is?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 2:56 pm 
Beginner
Beginner

Joined: Mon Sep 15, 2003 12:41 pm
Posts: 21
it's easy -- you're not in transaction.

the only things that I know which doesn't rollback -- are sequences.
well, and DDLs (CREATE TABLE,...) are not always transactional.

so -- you're not in transaction. show your code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:06 pm 
Newbie

Joined: Thu Jun 09, 2005 2:41 pm
Posts: 6
actually I am in transaction the code like this:
//get session
try {
session = factory().openSession();
tx = session.beginTransaction();
// do some things here like
session.load
session.delete
session.update
.....
.....
......

//here I tried to through excepion
throw new HibernateException("test rollback");
//tx.commit();
} catch (HibernateException he) {

if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack()
tx.rollback();
}
}
finally {

//TODO
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:11 pm 
Beginner
Beginner

Joined: Mon Sep 15, 2003 12:41 pm
Posts: 21
well, the code looks more or less fine, except it's not complete.
I wrote many of similar blocks, and it works. always.

add logging to see if your rollback is called actually.

check that your database supports transactions.
MySQL doesn't if it's not InnoDB tables.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:13 pm 
Beginner
Beginner

Joined: Mon Sep 15, 2003 12:41 pm
Posts: 21
check also autocommit option of your datasource.
as far as I understand, hibernate turns that off by itself, but who knows...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:15 pm 
Newbie

Joined: Thu Jun 09, 2005 2:41 pm
Posts: 6
The rollback method get called When I debuged it, one thing I think about maybe the problem comes from db side, I use Mysql, I will check it.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:17 pm 
Newbie

Joined: Thu Jun 09, 2005 2:41 pm
Posts: 6
dozen wrote:
check also autocommit option of your datasource.
as far as I understand, hibernate turns that off by itself, but who knows...

I set the flush mode to commit in my code. so its not that problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:19 pm 
Beginner
Beginner

Joined: Mon Sep 15, 2003 12:41 pm
Posts: 21
oneal wrote:
I use Mysql, I will check it.


That explains. Either InnoDB should be set as default table type,
or table should be created with InnoDB option:

CREATE TABLE ( ... ) Type="InnoDB";


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:26 pm 
Newbie

Joined: Thu Jun 09, 2005 2:41 pm
Posts: 6
dozen wrote:
oneal wrote:
I use Mysql, I will check it.


That explains. Either InnoDB should be set as default table type,
or table should be created with InnoDB option:

CREATE TABLE ( ... ) Type="InnoDB";


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 4:34 pm 
Newbie

Joined: Thu Jun 09, 2005 2:41 pm
Posts: 6
good news the problem comes from db side when I set table type to InnoDB every thing is work well.

Thank you guys


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