Discussion:
[nhusers] Nhibernate tries to UPDATE another table when i run select query
Yılmaz Demir
2018-09-27 18:25:14 UTC
Permalink
*C# Code:*

var query = Session.QueryOver<RealtyFile>(() => realtyFileAlias);
query = query.Fetch(sub => sub.Realty).Eager;

query = query.Inner.JoinAlias(() => realtyFileAlias.Realty, () =>
realtyAlias, realty => realty.Id == realtyFileAlias.RealtyId && !realty.
IsDeleted);


var retVal = query.Where(() => !realtyFileAlias.IsDeleted && realtyFileAlias
.TypeId == (int)RealtyFileType.Image)
.SelectList(builder => builder .Select(file => file.RealtyId)).List<int>();




*Exception:*
NHibernate.StaleStateException: 'Batch update returned unexpected row count
from update; actual row count: 0; expected: 1'


*SQL Server Profiler Trace:*

There are lots of UPDATE statements!!!
Update statements is not related to realty or realtyfile tables. This is
also interesting.
Ä° don't know why? Is there any comment please?
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Oskar Berggren
2018-09-27 18:52:06 UTC
Permalink
Which line exhibits the exception, what other tables are updated and what
are your mappings?
Post by Yılmaz Demir
*C# Code:*
var query = Session.QueryOver<RealtyFile>(() => realtyFileAlias);
query = query.Fetch(sub => sub.Realty).Eager;
query = query.Inner.JoinAlias(() => realtyFileAlias.Realty, () =>
realtyAlias, realty => realty.Id == realtyFileAlias.RealtyId && !realty.
IsDeleted);
var retVal = query.Where(() => !realtyFileAlias.IsDeleted &&
realtyFileAlias.TypeId == (int)RealtyFileType.Image)
.SelectList(builder => builder .Select(file => file.RealtyId)).List<int>
();
*Exception:*
NHibernate.StaleStateException: 'Batch update returned unexpected row
count from update; actual row count: 0; expected: 1'
*SQL Server Profiler Trace:*
There are lots of UPDATE statements!!!
Update statements is not related to realty or realtyfile tables. This is
also interesting.
Ä° don't know why? Is there any comment please?
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Yılmaz Demir
2018-10-01 13:48:33 UTC
Permalink
*Exception Line:*

var retVal = query.Where(() => !realtyFileAlias.IsDeleted && realtyFileAlias
.TypeId == (int)RealtyFileType.Image)
.SelectList(builder => builder .Select(file => file.RealtyId)).List<int>();





update for other tables that are not related in these tables mapping.
Tables: Package and Account

There are update processes for these tables before the query below.

*Mapping*:
Realty
...
HasMany(x =>
x.Files).KeyColumn("RealtyFileRealtyID").Inverse().Cascade.All().Not.LazyLoad().ExtraLazyLoad();
...

RealtyFile:
...
References(x =>
x.Realty).Column("RealtyFileRealtyID").Not.Nullable().Not.Insert().Not.Update();
...

And there is a topic about this. Can you check it also please?

https://stackoverflow.com/questions/8350855/batch-update-returned-unexpected-row-count-from-update-actual-row-count-0-exp/8363322


i modified the query for running on single table, Realty, for checking; and
there is not any exception.
Post by Oskar Berggren
Which line exhibits the exception, what other tables are updated and what
are your mappings?
Post by Yılmaz Demir
*C# Code:*
var query = Session.QueryOver<RealtyFile>(() => realtyFileAlias);
query = query.Fetch(sub => sub.Realty).Eager;
query = query.Inner.JoinAlias(() => realtyFileAlias.Realty, () =>
realtyAlias, realty => realty.Id == realtyFileAlias.RealtyId && !realty.
IsDeleted);
var retVal = query.Where(() => !realtyFileAlias.IsDeleted &&
realtyFileAlias.TypeId == (int)RealtyFileType.Image)
.SelectList(builder => builder .Select(file => file.RealtyId)).List<int>
();
*Exception:*
NHibernate.StaleStateException: 'Batch update returned unexpected row
count from update; actual row count: 0; expected: 1'
*SQL Server Profiler Trace:*
There are lots of UPDATE statements!!!
Update statements is not related to realty or realtyfile tables. This is
also interesting.
Ä° don't know why? Is there any comment please?
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Oskar Berggren
2018-10-01 19:35:54 UTC
Permalink
Post by Yılmaz Demir
*Exception Line:*
var retVal = query.Where(() => !realtyFileAlias.IsDeleted &&
realtyFileAlias.TypeId == (int)RealtyFileType.Image)
.SelectList(builder => builder .Select(file => file.RealtyId)).List<int>
();
update for other tables that are not related in these tables mapping.
Tables: Package and Account
There are update processes for these tables before the query below.
Are you saying that you have, in the same session and transaction, loaded
objects from Package and Account and made changes to these objects? If so,
please explain why you find it surprising that NHibernate may decided to
issue these UPDATE statements to the database?

As for the exception... well, I expect the problem is with the update code
that you haven't shown, and not with the query that you do show.

Explore the exception AND ALL inner exceptions to see if the message or
stacktrace may give a clue.

Also consider activating DEBUG-logs for NHibernate.SQL - this should show
which exact SQL-statement didn't go as NHibernate expected.

/Oskar
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Loading...