Composite-Id relationships (key-many-to-one) do not appear to be used in CreateCriteria
Description
Environment
Activity

Frederick Hirschfeld December 24, 2016 at 6:15 PM
Wish there was a way to delete or edit a comment .
Turns out my mapping had the CompositeId defined with a KeyReference and then (at least up to 3.3.1) we also had a mapping for the reference defined to get around this bug and once the fix for this was in place AND I removed that additional reference mapping, the issues we were seeing went away. No new bug but others that experience this should remove the additional Reference mapping.

Frederick Hirschfeld December 24, 2016 at 5:55 PM
Unfortunately this fix now causes another issue of duplicate joins when the query (for select purposes) joins on the reference in the composite id. An example of this would be where you want to fetch all the records and then do some projections of values from the parent record. I will log an issue for this specific broken usage.

Daniel A. Schilling August 2, 2012 at 1:06 PM
Sweet! Here's another work-around to tide people over until the next version of NHibernate is released: because has been fixed since v2.1.1, you can avoid this bug by extracting your composite key out to it's own class as described here: http://nhforge.org/doc/nh/en/index.html#components-compositeid. Please note that you will also have to change any code that refers to the composite-id properties. For example, if you previously referred to the property like "child.Parent", now you will have to do "child.Id.Parent".

Alex Zaytsev August 2, 2012 at 8:15 AM
Pull request by Daniel A. Schilling merged to master

Daniel A. Schilling August 2, 2012 at 2:59 AM
... and is another duplicate. is related but distinct. This issue (NH-2033), NH-2469, and apply to embedded composite id's (composite-id's with no "name" attribute), while applies to named composite-id's.
Details
Details
Assignee

Reporter

Please see http://itcodemonkey.blogspot.com/2009/12/nhibernate-querying-across-composite.html for full details.
Basically, using a composite id (legacy DB!) and trying to createCriteria across that relationship does not work. There is no inner join on that table and therefore errors when trying to query fields from that table.