Hi,
Here is 2 lines of code, the first one is running, the second one generate an error. Why ???
I use Hibernate 3.0.2 and Spring 1.2rc2
Code:
// This one is OK
final Iterator it = getHibernateTemplate().find("select p from Person p, Address a where a.fk_pers = p.id_pers and a.zip = ? ", param).iterator();
// This one is KO
final Iterator it = getHibernateTemplate().find("from Person p, p.addresses where zip = ? ", param).iterator();
I have the next in the Person.hbm.xml
Code:
<set
name="addresses"
lazy="true"
inverse="true"
cascade="all"
>
<key>
<column name="FK_PERS" />
</key>
<one-to-many
class="com.model.Address"
/>
</set>
I have the next message:
...
INFO: Mapping collection: com.model.Person.addresses -> ADDRESS
May 6, 2005 10:52:10 PM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
...
SEVERE: *** ERROR: p.addresses is not mapped.
org.springframework.orm.hibernate3.HibernateQueryException: p.addresses is not mapped. [from com.model.Person p, p.addresses where zip = ? ]; nested exception is org.hibernate.hql.ast.QuerySyntaxError: p.addresses is not mapped. [from com.model.Person p, p.addresses where zip = ? ]
org.hibernate.hql.ast.QuerySyntaxError: p.addresses is not mapped. [from com.model.Person p, p.addresses where zip = ? ]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:196)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:422)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:822)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:748)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:310)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:739)
at com.dao.hibernate.PersonDAOHibernate.findByZip(PersonDAOHibernate.java:90)
at com.dao.PersonDAOTest.testFindByZip(PersonDAOTest.java:63)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
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:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Caused by: p.addresses is not mapped.
at org.hibernate.hql.ast.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:85)
at org.hibernate.hql.ast.FromElementFactory.addFromElement(FromElementFactory.java:77)
at org.hibernate.hql.ast.FromClause.addFromElement(FromClause.java:67)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:217)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2830)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
... 26 more
Why does it happening? Is it a bug or do i miss use Spring/Hibernate ?
(I have the same problem with jboss ejb 3.0 and same kind of syntax)
Thanks for your help.
JMi
Hibernate version:
3.0.2
Mapping documents:
<set
name="addresses"
lazy="true"
inverse="true"
cascade="all"
>
<key>
<column name="FK_PERS" />
</key>
<one-to-many
class="com.model.Address"
/>
</set>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
I have the next message:
...
INFO: Mapping collection: com.model.Person.addresses -> ADDRESS
May 6, 2005 10:52:10 PM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
...
SEVERE: *** ERROR: p.addresses is not mapped.
org.springframework.orm.hibernate3.HibernateQueryException: p.addresses is not mapped. [from com.model.Person p, p.addresses where zip = ? ]; nested exception is org.hibernate.hql.ast.QuerySyntaxError: p.addresses is not mapped. [from com.model.Person p, p.addresses where zip = ? ]
org.hibernate.hql.ast.QuerySyntaxError: p.addresses is not mapped. [from com.model.Person p, p.addresses where zip = ? ]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:196)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:422)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:822)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:748)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:310)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:739)
at com.dao.hibernate.PersonDAOHibernate.findByZip(PersonDAOHibernate.java:90)
at com.dao.PersonDAOTest.testFindByZip(PersonDAOTest.java:63)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
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:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Caused by: p.addresses is not mapped.
at org.hibernate.hql.ast.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:85)
at org.hibernate.hql.ast.FromElementFactory.addFromElement(FromElementFactory.java:77)
at org.hibernate.hql.ast.FromClause.addFromElement(FromClause.java:67)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:217)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2830)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
... 26 more
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: