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 <[email protected]> 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 > () in C:\Work\NHibernate\Full Source\src\src\NHibernate\Loader\Criteria > \CriteriaQueryTranslator.cs: line 343 > at NHibernate.Loader.Criteria.CriteriaQueryTranslator..ctor > (ISessionFactoryImplementor factory, CriteriaImpl criteria, String > rootEntityName, String rootSQLAlias) in C:\Work\NHibernate\Full Source > \src\src\NHibernate\Loader\Criteria\CriteriaQueryTranslator.cs: line > 59 > at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable > persister, ISessionFactoryImplementor factory, CriteriaImpl > rootCriteria, String rootEntityName, IDictionary`2 enabledFilters) in > C:\Work\NHibernate\Full Source\src\src\NHibernate\Loader\Criteria > \CriteriaLoader.cs: line 34 > at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList > results) in C:\Work\NHibernate\Full Source\src\src\NHibernate\Impl > \SessionImpl.cs: line 1908 > at NHibernate.Impl.CriteriaImpl.List(IList results) in C:\Work > \NHibernate\Full Source\src\src\NHibernate\Impl\CriteriaImpl.cs: line > 246 > at NHibernate.Impl.CriteriaImpl.List<T>() in C:\Work\NHibernate\Full > Source\src\src\NHibernate\Impl\CriteriaImpl.cs: line 257 > > Here is the code for GetAssociatedEntityName > public string GetAssociatedEntityName(ISessionFactoryImplementor > factory) > { > try > { > IQueryableCollection collectionPersister = > (IQueryableCollection) > factory.GetCollectionPersister(role); > > if > (!collectionPersister.ElementType.IsEntityType) > { > throw new > MappingException("collection was not an association: " > + collectionPersister.Role); > } > > above code collectionPersister.ElementType.IsEntitype is false becase > ElementType is ComponentType. > > Is there is a reason why ComponentType are not queryable. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
