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.  [ 5 posts ] 
Author Message
 Post subject: problem related sharing transaction between NH and ADO.NET
PostPosted: Fri Aug 04, 2006 5:58 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
I m facing one problem here is the scenario

1> I m inserting a row into a table using NH and i m mofifying the same row , but all i need to do in single transaction , my update code is i m doing through SP
2> So my code sequence is like this
a> BeginTransaction

b> Inserting a record using NH
c> Create command object , Enlist that command object with
session.Transaction.Enlist(cmd)
d> cmd.ExcecuteNonquery()
e> commit the transaction

so i ahve table say Members which contains ID, name, rollupmap columns,
I m inserting a row having values for name, ID using NH code
using SP i m updating rollupmap column

This does not work, it stores only null value, because it does not get the record just inserted.

Now with ADO.NET
All the steps are done using ADO.NET inseted of NH
1> BeginTransaction
2> Insert a record
3> Update a record
4> Commit the transaction

What i observe that i updates rollupmap value properly
====================
Can anyone give any input on this ?????????


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 04, 2006 8:49 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Are you calling Flush()?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 04, 2006 12:14 pm 
Newbie

Joined: Fri Dec 09, 2005 2:22 pm
Posts: 16
I had the same problem:
- NH flushes your updates when it needs to
- your ADO queries are executed right away

the queries may not be executed in the correct order !

so before each of your ADO insert/updates you need to call session.flush() to avoid any inconsistencies (nonexisting foreign keys...).
I call everything in the same transaction using transaction.enlist(command) for the ADO part.


Top
 Profile  
 
 Post subject: Sharing the session
PostPosted: Mon Aug 07, 2006 2:10 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
Yes i m calling flush, but calling flush means commiting the transaction , so there will be no chance of rollback.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 3:19 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Calling flush does not commit the Tx. It simply sends outstanding commands to the database. If you start a transaction it will not be committed until you explicitly call Transaction.Commit().

Symon.


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