Description
Anup Marwadi created an issue — 12th November 2009, 13:32:15:
Hello All,
This is a bug I have noticed on my current NHibernate project. I tried to search for it on this forum and don't know if it has been rectified as of yet or not. However, the explanation for this bug is provided here:
http://derek-says.blogspot.com/2008/06/duplicate-association-path-bug-in.htmlI would like to know if there is a way using criteria API to create multiple aliases that point to the same table. I would highly appreciate it if you could share any information on the same.
My criteria is pretty simple:LeadManager manager = new LeadManager(); ISession mySession = manager.Session.GetISession(); ICriteria criteria = mySession.CreateCriteria(typeof(Lead)); criteria.SetProjection(Projections.Distinct(Projections.Property("Id"))); criteria.Add(Expression.Eq("CustomerId", 950)); criteria.CreateAlias("CandidateMember", "candidate"); criteria.CreateAlias("candidate.ExtensionValues", "extensions"); criteria.CreateAlias("extensions.ExtensionValueTypeMember", "extensionTypes"); Conjunction c = new Conjunction(); c.Add(Expression.Eq("extensionTypes.Id", 1)); c.Add(Expression.In("extensions.ExtensionDatum", new object[] { 'A', 'B' })); criteria.Add(c); criteria.CreateAlias("candidate.ExtensionValues", "extensions1"); criteria.CreateAlias("extensions1.ExtensionValueTypeMember", "extensionTypes1"); Conjunction c1 = new Conjunction(); c1.Add(Expression.Eq("extensionTypes.Id", 2)); c1.Add(Expression.In("extensions.ExtensionDatum", new object[] { 'A', 'B', 'C', 'D' })); criteria.Add(c1); criteria.SetMaxResults(10); long[] leadIds = criteria.List<Int64>().ToArray();
Robert Dal Santo added a comment — 17th September 2011, 15:44:15:
This issue is related to https://nhibernate.jira.com/browse/NHLQ-43 and a duplicate of the Hibernate defect/limitation https://hibernate.onjira.com/browse/HHH-879.
This limitation causes me to create ICriteria queries using subqueries, which will almost certainly result in sub-optimal execution plans. I'd rather not, but this might force me to abandon ICriteria and use native-SQL instead, which will result in much more verbose logic.