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: NHibernate and triggers
PostPosted: Tue Nov 20, 2007 12:39 pm 
Newbie

Joined: Mon Jan 08, 2007 10:29 am
Posts: 3
Hibernate version:
1.0.2

NHibernate and triggers
The following exception in application based on SQL Server 2005 and NHibernate :

[NHibernate.AdoNet.TooManyRowsAffectedException] {"Unexpected row count: 2; expected: 1"} NHibernate.AdoNet.TooManyRowsAffectedException

After a quick investigation the problem was obvious - the exception raises when a row from a table is updated and the row has fired a trigger which executes an update statement.

I have faced with this problem since early beta of NHibernate (0.8.4 as far as I can remember). Till now the only solution I have found is to use SET NOCOUNT to stop the message that shows the number of rows affected by a Transact-SQL statement from being returned as part of the results.

the solution found on the web doesn't really make me happy:
Just place SET NOCOUNT ON before the UPDATE statement inside the trigger and then after the UPDATE statement place SET NOCOUNT OFF. This will solve the problem.

Is there another way to solve this ??

Any help apreciated !
Thank you !
Stephan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 2:47 pm 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
Not sure there's another way to solve this but setting NO COUNT ON in triggers is considered a best practice. I always turn this on in every trigger.


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.