-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Criteria API and joins problem
PostPosted: Fri Feb 04, 2005 12:00 pm 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
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

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 7:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
use createCriteria() or createAlias(), there are no implicit joins in criteria queries.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 8:04 pm 
Newbie

Joined: Tue Oct 05, 2004 11:22 am
Posts: 8
I encountered a similar problem in Hibernate 2 recently. It sounds like Hibernate 3 works the same way. The solution he gave me is in this thread:

http://forum.hibernate.org/viewtopic.php?t=933883


Top
 Profile  
 
 Post subject: Solved
PostPosted: Tue Feb 08, 2005 1:03 pm 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
OK, thanks all. Changing the code to the followings solves the problem:
Code:
Collection result = getSession().createCriteria( Articolo.class ).add( Expression.ilike( "id", getQ(), MatchMode.START ) ).createCriteria( "genere" ).add( Expression.eq( "categoria.id", Long.toString( id ) ) ).list();

_________________
--
Marco


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.