Hi, I'm experiencing a strange behaviour with the criteria API.
I'm using the Antlr query parser and everything is ok during initialization.
When I try to use the following criteria I get an error:
Code:
Collection result = getSession().createCriteria( Articolo.class ).add( Expression.ilike( "id", getQ(), MatchMode.START ) ).add( Expression.eq( "genere.nome", id ) ).list();
As the stack trace says, Hibernate can't resolve the property 'genere.nome'. If I change the criterion to "genere.id", everything it's ok and Hibernate generates the following query:
Code:
16:41:33,563 DEBUG SQL:297 - select this_.ID as ID0_, this_.CATALOGO as CATALOGO2_0_, this_.GENEREID as GENEREID2_0_ from ARTICOLO this_ where lower(this_.ID) like
? and this_.GENEREID=?
Could someone shed some light on this? What I'm doing wrong ? I'm pretty sure that this works in hibernate2...
Hibernate version:Hibernate3 beta 3
Mapping documents:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="web.model.Articolo"
table="ARTICOLO"
>
<id
name="id"
type="java.lang.String"
column="ID"
>
<generator class="assigned" />
</id>
<property
name="catalogo"
type="java.lang.String"
column="CATALOGO"
length="64"
/>
...
<many-to-one
name="genere"
class="web.model.Genere"
not-null="false"
outer-join="auto"
>
<column name="GENEREID" />
</many-to-one>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="web.model.Genere"
table="GENERE"
>
<id
name="id"
type="long"
column="ID"
>
<generator class="assigned" />
</id>
<property
name="nome"
type="java.lang.String"
column="NOME"
length="64"
/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():I'm using webwork 2.1 with HibernateHinterceptor written by Gavin King forn hibernate 2 and adapted to the new version.
Full stack trace of any exception that occurs:Code:
15:41:26,936 ERROR HibernateInterceptor:44 - HibernateException in execute()
org.hibernate.QueryException: could not resolve property: genere.nome of: web.model.Articolo
at org.hibernate.persister.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:63)
at org.hibernate.persister.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:33)
at org.hibernate.persister.BasicEntityPersister.toColumns(BasicEntityPersister.java:1007)
at org.hibernate.loader.CriteriaQueryTranslator.getPropertyColumns(CriteriaQueryTranslator.java:319)
at org.hibernate.loader.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:310)
at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:42)
at org.hibernate.loader.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:259)
at org.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:87)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1585)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:257)
at web.action.RicercaArticoloAction.searchByCodice(RicercaArticoloAction.java:115)
at web.action.RicercaArticoloAction.go(RicercaArticoloAction.java:87)
at web.action.AbstractAction.execute(AbstractAction.java:189)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:169)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:166)
at web.component.HibernateInterceptor.intercept(HibernateInterceptor.java:34)
...
Name and version of the database you are using:
OracleDB 9.2.0.5
The generated SQL (show_sql=true):
none