-->
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: session.connection().commit() does not commit ?
PostPosted: Wed Dec 07, 2005 10:26 am 
Newbie

Joined: Wed Dec 07, 2005 10:13 am
Posts: 3
Hi,

I'm using Hibernate with JTA without problem in several projects, but I'm facing problems using Hibernate with JDBC transactions :

When inserting/updating a row, I'm forced to use
session.beginTransaction().commit() in the end of my code.
If I don't, nothing is done. Even when calling session.connection().setAutoCommit(true) before the operation.

There must be some obvious reason but I just I can't see...
Please, can someone explain me this behaviour ? I have found no clue in the forum...
Thank you for your help.

I'm using Hibernate 3.0.5 / Tomcat 5.0.28 / PostgreSQL 8.1 / JDBC driver build 404


Best regards.
--
Xavier Bugaud


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 1:20 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
session.beginTransaction().commit() starts and commits the transaction in one line of code. try starting the transaction, actually doing work, and then committing .


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 1:23 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
maybe you can elaborate on how jta is being used here?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 1:32 am 
Newbie

Joined: Wed Dec 07, 2005 10:13 am
Posts: 3
Hi Dennis,

Thank you for answering.

dennisbyrne wrote:
maybe you can elaborate on how jta is being used here?

In my other projects, I use the JOTM transaction manager inside the Jonas container.

dennisbyrne wrote:
session.beginTransaction().commit() starts and commits the transaction in one line of code. try starting the transaction, actually doing work, and then committing .

According to the API doc, session.beginTransaction().commit() start a new transaction only if necessary, so I guess there is already an existing transaction when I'm calling session.beginTransaction(), don't you think ?

The following code actually works :
Code:
Transaction tx = session.beginTransaction();
   ...
tx.commit()


But I just can't explain why session.connection().setAutoCommit(true) does not work...


Best regards.
--
Xavier Bugaud


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 2:08 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Xavier Bugaud wrote:
According to the API doc, session.beginTransaction().commit() start a new transaction only if necessary


can you show me where it says this?

the code that "actually works" is what I meant in the first response.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 2:35 am 
Newbie

Joined: Wed Dec 07, 2005 10:13 am
Posts: 3
dennisbyrne wrote:
Xavier Bugaud wrote:
According to the API doc, session.beginTransaction().commit() start a new transaction only if necessary


can you show me where it says this?

the code that "actually works" is what I meant in the first response.


Here : http://www.hibernate.org/hib_docs/v3/ap ... ansaction()

(...) If a new underlying transaction is required, begin the transaction. Otherwise continue the new work in the context of the existing underlying transaction. (...)

Sorry, I just realize there is a typo in my previous message : I wanted to say session.beginTransaction() instead of session.beginTransaction().commit().

But do you know why session.connection().setAutoCommit(true) does not automatically commit the transaction ? Is this a bug ?

Best Regards.
--
Xavier Bugaud


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 5:14 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
The setAutoCommit is turned off in the JDBCTransaction code because there are certain cleanup tasks that need to be done after the commit. Setting autoCommit does not give Hibernate an oppurtunity to do those.
Check net.sf.hibernate.transaction.JDBCTransaction's beginTransaction method where this is turned off.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.