I'm having the same problem. This seems to be a problem in hibernate
aswell although there have abeen a few patches none of which I believe
have been applied.
This seems like such a pitfall of the Criteria API with the only
workaround being a Restrictions.SqlProjection which is really
horrible.
Does any one know if this is being addressed or will be addressed,
does anyone else care?
On Aug 25, 5:06 pm, raj <
dsenthil...@gmail.com> wrote:
> I have Department entity it has list of Employees connected via
> EmployeeRole
>
> My mapping look list this
> <Class name="Department" ...>
>
> <set name="Employees" table ="SYSTEM_EMPL_ROLE">
> <key column ="Department_Id" foreign-key
> ="Department_EMPL_ROLE_FK2"/>
> <composite-elementclass ="EmployeeRoleEntity">
> <property column ="EMPL_TYPE_CODE" name ="EmployeeRoleType"/>
> <property column ="EMPL_ID" name ="EmployeeId"/>
> </composite-element>
> </set>
> </class>
> when i wrote following HQL it works
> select entity
> from DepartmentEntity entity
> join entity.Employees empl
> where empl.EmployeeId =100
> and empl.EmployeeRoleType= 'Manager'
>
> but if i do the same in Criteria object i get following errror
> NHibernate.MappingException: collection was not an association:
> DepartmentEntity.Employees
>
> Query stack for the exception
> at NHibernate.Type.CollectionType.GetAssociatedEntityName
> (ISessionFactoryImplementor factory) in CollectionType.cs: line 315
> at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetPathEntityName
> (String path) in C:\Work\NHibernate\Full Source\src\src\NHibernate
> \Loader\Criteria\CriteriaQueryTranslator.cs: line 359
> at
> NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateCriteriaEntityNameMap