NHibernate version:
1.2.0.4000
Mapping documents:
(abreviated for clarity)
Code:
<hibernate-mapping auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
<class name="FRS.Business.Job, FRS.Entities" table="JOBS">
<id name="Id" access="property" column="JOBID" type="Int32" unsaved-value="0">
<generator class="sequence">
<param name="sequence">JOBSPK</param>
</generator>
</id>
<bag name="Vehicles" access="field.camelcase-underscore" table="VEHICLES" lazy="false">
<key column="JOBID" />
<one-to-many class="FRS.Business.Vehicle, FRS.Entities" />
</bag>
</class>
<class name="FRS.Business.Vehicle, FRS.Entities" table="VEHICLES">
<id name="Id" access="property" column="VEHICLEID" type="Int32" unsaved-value="0">
<generator class="native">
<param name="sequence">VEHICLESPK</param>
</generator>
</id>
<many-to-one name="Job" access="property" class="FRS.Business.Job, FRS.Entities" column="JOBID" />
<bag name="RunningVehicles" access="field.camelcase-underscore" table="RUNNINGVEHICLES" lazy="false">
<key column="VEHICLEID" />
<one-to-many class="FRS.Business.RunningVehicle, FRS.Entities" not-found="ignore" />
</bag>
<joined-subclass name="FRS.Business.StandByVehicle, FRS.Entities" table="STANDBYS">
<key column="VEHICLEID" />
</joined-subclass>
</class>
<class name="FRS.Business.RunningVehicle, FRS.Entities" table="RUNNINGVEHICLES">
<id name="Id" access="property" column="RUNNINGVEHICLEID" type="Int32" unsaved-value="0">
<generator class="sequence">
<param name="sequence">RUNNINGVEHICLESPK</param>
</generator>
</id>
<many-to-one name="Vehicle" access="field.camelcase-underscore" class="FRS.Business.Vehicle, FRS.Entities" column="VEHICLEID" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
DetachedCriteria criteria = DetachedCriteria.For(typeof(Job), "j")
.CreateAlias(Job.Properties.Vehicles, "v", JoinType.LeftOuterJoin)
.CreateAlias("v." + Vehicle.Properties.RunningVehicles, "r", JoinType.LeftOuterJoin);
//go on to use the criteria as a subquery
Full stack trace of any exception that occurs:Code:
NHibernate.QueryException: duplicate alias: j
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateAliasCriteriaMap()
at NHibernate.Loader.Criteria.CriteriaQueryTranslator..ctor(ISessionFactoryImplementor factory, CriteriaImpl criteria, Type rootEntityName, String rootSQLAlias)
at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, Type rootEntityName, IDictionary enabledFilters)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results)
at NHibernate.Impl.SessionImpl.Find[T](CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List[T]()
Name and version of the database you are using:
Oracle 10g
Diagnosis
This problem seems to be limited to DetachedCriteria.
If I try and do the same thing with session.CreateCriteria, it works fine.
Also, changing the CreateAlias to CreateCriteria works fine.
However, I can't do either of these as I need to left outer join on more than one child of the Job and this is part of a sub query.
Is this a limitation or a bug?
Thanks