Strange bug when querying a circular graph with several joins
"Chris Smith" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nhibernate.devel |
|---|---|
| Message-ID | <93BA6C2C05B6974A9F25DA49D4F046BA0256FE84@EXVBE014-13.exch014.msoutlookonline.net> |
[I submitted this originally with the patch attached and fell fowl of
the 40k limit. I then got a rejection with "No reason given" and
wondered if that was automatic after a certain time. If this isn't the
right list to be posting to, can you please point me in the right
direction? It seems like a development issue, but that's not for me to
judge.]
Dear All
We are using NHibernate for our main data-driven product and we have run
into a problem that is causing us headaches. A bit of background on our
domain model, if I may:
We write patient records software for hospitals. We have a Session
class that represents the logged in user. That user has a Role, e.g.
consultant, which is a property of the Session.
All of our entities have a Session associated with them, which allows us
to audit changes. In particular, we list doctors in our system as a
collection of Role entities, each of which has a Session.
A Role has a Location object as a member and that Location has a Session
and an Address, the Address in turn having a Session.
The point of this is that a Role may represent both the user of the
system and someone they would be interested in, say, assigning a task
to, e.g. another doctor.
All that to say that there is circularity in the dependencies, although
not necessarily in any given object graph, i.e. a Role has a Session
which has a Role, etc.
We have run into problems because we are querying roles using the
ICriteria API. If I do this within an NHibernate session:
IQuery query = NHsession.CreateQuery("from Role role where
role.PrimaryLocation.Address.Postcode like 'BS%'");
IList<Role> roles = query.List<Role>();
Assert.AreEqual(1, roles.Count);
all is well.
However, if I then do this:
ICriteria criteria = NHsession.CreateCriteria(typeof(Role));
criteria.CreateAlias("PrimaryLocation.Address",
"primarylocation_address");
criteria.Add(Expression.Like("primarylocation_address.Postcode",
"BS%"));
Assert.AreEqual(1, criteria.List().Count);
an exception is thrown saying that
The multi-part identifier "primaryloc1_.Postcode" could not be bound
Looking at the SQL generated for this query (which is very long) shows
that it ends with
WHERE primaryloc1_.Postcode like ?
This is failing because the alias primaryloc1_ is never declared in the
SQL.
We have debugged into the NHibernate source but are having trouble
pinpointing the problem. Does anyone on this list know where we should
be looking?
I have written a breaking unit test in the NHibernate.Test-3.5 project
which I can supply as a patch.
All help gratefully received.
Regards
Chris Smith
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Nhibernate-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nhibernate-development