Hi guys,

I posted an issue I was seeing to nhusers because when i started I was
sure I was doing something stupid (which is still possible), but not
too long after posting there I found something in the
SingleTableEntityPersister that seems to be causing my issue.  I'm
using version 2.0.1 but the issue seems to have been around for a good
while.

The summary in my original post is tough to read, you guys will
probably find it easier to just look at the change I made.  To
summarize it a little better here, I've got a table per hierarchy
mapping strategy and a class with 2 one-to-many collections of
different types (all types are in this class hierarchy).  The
relationships are bidirectional parent/child type, but I'd like the
children split into these two collections instead of all being in one
big Children collection.  Without my patch, NHibernate wasn't
generating a WHERE clause based on discriminators when loading those
collections and it was actually causing it to hydrate a database
record of one type as an instance of another, corrupting the session's
cache.

It's this thread ( 
http://groups.google.com/group/nhusers/browse_thread/thread/d2baeaa5c2be4956
), I've gone through and made the change and run the NUnit tests in
NHibernate.Test.dll, the same tests succeed and fail with or without
my patch.  The queries generated with this patch seem more correct for
me, I've tested with one-to-many mappings of subclasses, with derived
subclasses, joined-subclasses, and standalone class mappings, all of
those scenarios seem to work.

I'm going to create a JIRA ticket but I was looking through the
history of SingleTableEntityPersister and this code hasn't been
changed in a good while, so I wanted to see if you guys had any input
first.

The patch would end up being this:

Index: SingleTableEntityPersister.cs
===================================================================
--- SingleTableEntityPersister.cs       (revision 3917)
+++ SingleTableEntityPersister.cs       (working copy)
@@ -522,7 +522,7 @@

                public override string OneToManyFilterFragment(string
alias)
                {
-                       return forceDiscriminator ?
DiscriminatorFilterFragment(alias) :
string.Empty;
+                       return DiscriminatorFilterFragment(alias);
                }

                private string DiscriminatorFilterFragment(string
alias)




Thanks,
Jon

Reply via email to