Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
v3.1.3
Mapping documents:
A Notice has a reference to multiple Statusses.
Code between sessionFactory.openSession() and session.close():
DetachedCriteria criteria1 = DetachedCriteria.forClass(Notice.class);
DetachedCriteria criteria2 = DetachedCriteria.forClass(Status.class);
criteria1.add(Subqueries.exists(criteria2));
getHibernateTemplate().findByCriteria(criteria1);
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateSystemException:
Unknown entity: com.notary.app.taxsocnot.notice.model.Status; nested exception is org.hibernate.MappingException: Unknown entity: com.notary.app.taxsocnot.notice.model.Status
org.hibernate.MappingException: Unknown entity: com.notary.app.taxsocnot.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.notary.app.taxsocnot.notice.dao.NoticeDAOImpl.query(NoticeDAOImpl.java:48)
at com.notary.app.taxsocnot.notice.service.NoticeManagerImpl.query(NoticeManagerImpl.java:75)
at com.notary.app.taxsocnot.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:705)
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.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
at com.notary.app.taxsocnot.notice.service.NoticeManagerImpl$$EnhancerByCGLIB$$67d7ae35_2.query(<generated>)
at com.notary.app.taxsocnot.notice.test.NoticeManagerTestCase.testFindOnNoticeData(NoticeManagerTestCase.java:1102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Name and version of the database you are using:
SQLServer 2000
The generated SQL (show_sql=true):
Exception is thrown before the sql has been generated.
Debug level Hibernate log excerpt:
N/A
-I would like to get all Notices for which the status is 'Open'. In order to achieve this, I would like to have something similar to this SQL statement:
select * from t_notice notice where exists (select id from t_status status where status.state='Open' and status.noticeId = notice.id)
-When using a DetachedCriteria together with an "exists" subquery, a HibernateSystemException is generated. When using
session.createQuery("from om.notary.app.taxsocnot.notice.model.Notice notice where exists (select id from com.notary.app.taxsocnot.notice.model.Status status where status.state = 'Open' and status.noticeId = notice.id)") the query returns a correct result. Therefor, I am pretty sure that the mapping documents are correct and that the required entity exists.
-Reversing
Notice.class and
Status.class, generates the underneath listed stack trace:
org.springframework.orm.hibernate3.HibernateSystemException:
Unknown entity: com.notary.app.taxsocnot.notice.model.Notice; nested exception is org.hibernate.MappingException: Unknown entity: com.notary.app.taxsocnot.notice.model.Notice
org.hibernate.MappingException: Unknown entity: com.notary.app.taxsocnot.notice.model.Notice
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
...
-Is it possible that this issue is linked with
http://opensource.atlassian.com/project ... se/HHH-158?
-If
Subqueries.exists is not supported by the DetachedCriteria class, I would like to replace it with something similar to:
criteria1.addWhereClause("where exists (select id from com.notary.app.taxsocnot.notice.model.Status status where status.state = 'Open' and status.noticeId = notice.id)". Is this possible or is there another alternative?