All,
I am trying to transform an existing HQL query into a query that uses a DetachedCriteria. The existing HQL query has a NON EXISTS clause and is working fine.
The definition of a NON EXISTS subquery with my DetachedCriteria generates the following error:
Unknown entity: com.test.notice.model.Status.
Model: A Notice object has a set of Status objects. The HQL query returns all notices for which no 'Deleted' status exists.
Existing HQL query:
Code:
from com.test.model.NoticeImpl n where not exists (from com.test.model.StatusImpl s where s.notice = n and s.state = 'Deleted')
DetachedCriteria: Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Notice.class);
DetachedCriteria subCriteria = DetachedCriteria.forClass(Status.class,"subStatusses");
subCriteria.add(Restrictions.eq("subStatusses.notice","notice"));
subCriteria.add(Restrictions.eq("subStatusses.state",Status.DELETED));
criteria.add(Subqueries.notExists(subCriteria));
The HQL query is working fine, so I am pretty sure that the entity
com.test.notice.model.Status exists.
What am I doing wrong OR is there an alternative to implement the required functionality ?
Hibernate version:
3.1.3
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.test.notice.model.Status; nested exception is org.hibernate.MappingException: Unknown entity: com.test.notice.model.Status
org.hibernate.MappingException: Unknown entity: com.test.notice.model.Status
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:46)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:333)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1514)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.springframework.orm.hibernate3.HibernateTemplate$37.doInHibernate(HibernateTemplate.java:988)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:978)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:971)
at com.test.notice.dao.NoticeDAOImpl.query(NoticeDAOImpl.java:41)
at com.test.notice.service.NoticeManagerImpl.query(NoticeManagerImpl.java:94)
at com.test.notice.service.NoticeManagerImpl$$FastClassByCGLIB$$7e317016.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:685)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:623)