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.  [ 3 posts ] 
Author Message
 Post subject: assigned keys commit -> Unexpected row count: 2; expected
PostPosted: Wed Jun 13, 2007 6:20 am 
Newbie

Joined: Thu May 12, 2005 10:40 am
Posts: 16
I Upgraded from NHibenate 1.2 CR1 to 1.2 GA.
i'm using nhbibernate for mapping legacy things.
that's why i've to use assigned keys for some tables :-(
i'm using SAVE and Update as suggested,
so seems ok to me.

Since 1.2GA my nunit-tests fail when i create new entitys and attach
additional data to these entrys in the same session.

Things worked fine in 1.2 CR1 and all versions before since (0.8.0)
i think nhibernate trys to persist my data twice now.
Now i get 'Unexpected row count: 2; expected: 1' exception during commit...

Maybe there's a need now, to save bofore attaching aditional data ?

But i also might be a general trouble with asigned keys now, that's why i want to know if i'm doing something wrong.
(i also removed unsaved-value="null" which i had before in key-mapping, but didn't solve anything)

Would be great to hear any new ideas...

i tryed to 'reduce the problem as far as possible'

greetings
helmut

Hibernate version:
1.2.GA
Mapping documents:
Code:
<class name="MyClass" table="my_tab">
<id name="Id" column="MyId" type="String">
  <generator class="assigned"/>
</id>
...
<set name="ExtraData" table="my_extra_tab" cascade="delete" lazy="false">
         <key column="ClassId"></key>
         <composite-element class="blabla">
          ....
</set>


Code between sessionFactory.openSession() and session.close():
Code:
      MyClass oCls = new MyClass();
      oCls.Id = "testId1";
      ...
      // we want to have additiona data imediately too...
      oCls.ExtraData.Add(new ExtraData(blabla,,..));
      ...
      m_tx = session.BeginTransaction();
      session.Save(oCls);  // Save for new instances
      m_tx.Commit();  // Here the exception is thrown...

Full stack trace of any exception that occurs:
Code:
....
NHibernate.Impl.SessionImpl.Execute(:0) NHibernate.Impl.SessionImpl.Execute(:0) [(null)] - could not synchronize database state with session
NHibernate.AdoNet.TooManyRowsAffectedException: Unexpected row count: 2; expected: 1
....

Name and version of the database you are using:
mssql2005 in 2000 compatibility mode
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html[/code]


Top
 Profile  
 
 Post subject: Triggers
PostPosted: Fri Jun 15, 2007 1:45 pm 
Newbie

Joined: Fri Jun 15, 2007 1:35 pm
Posts: 1
Not sure if your problem is the same as mine but I am tinkering with NHibernate and just got this message myself. The problem I have is that my table has various triggers listening for inserts and updates. Any rows affected by a trigger gets added to the row count returned back to NHibernate.

To verify this, just run the SQL emitted by NHibernate, in my case I have:

(0 row(s) affected)

(3 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)


What I've seen people suggest is to alter the trigger as such:

SET NOCOUNT ON
-- Trigger actions
SET NOCOUNT OFF

My question to the community is: What if this is not an option? I have a legacy database that can't easily be adapted to fit NHibernate's wishes. I'll probably start browsing the NHibernate source code after this, but can we have an option to turn off this row count check (as inadvisable as that may be)?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 6:29 am 
Newbie

Joined: Thu May 12, 2005 10:40 am
Posts: 16
DRapp,
you made my week :-))

AARGHHH.
YESSS.. there is a trigger watching on this table,
which insert's a row in another table on inserts.

I think i would never have found out for myself,
that this is the reason of getting duplicate row count...
will have a try on 'SET NOCOUNT ON' as you suggested, now...

Thanks
Thanks
Thanks :-))))

Helmut


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