-->
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.  [ 7 posts ] 
Author Message
 Post subject: Problem using find method with composite-id based query
PostPosted: Fri Jan 30, 2004 5:22 pm 
Newbie

Joined: Fri Jan 30, 2004 5:10 pm
Posts: 7
Location: S
Hello.

I'm new to Hibernate.
I'm having problem on performing a query using a composite-id key. My schema was generated by Middle-Gen.

I'm using the following query:
Code:
String id="10";
List params = s.find("from Parameter as parameter where parameter.comp_id.id = ?",id,Hibernate.STRING);


Following is the hbm map file:
Code:
<class
    name="com.test.Parameter"
    table="PARAMETERS"
>
    <composite-id name="comp_id" class="com.test.ParameterPK">
        <key-property
            name="id"
            column="ID"
            type="java.lang.String"
            length="30"
        />
        <key-property
            name="value"
            column="VALUE"
            type="java.lang.String"
            length="40"
        />
    </composite-id>   
    <property
        name="description"
        type="java.lang.String"
        column="DESCRIPTION"
        length="50"
    />
</class>


When executing, it throws the following exception:
Code:
net.sf.hibernate.QueryException: unexpected token: as [from Parameter as parameter where parameter.comp_id.id = ?]
        at net.sf.hibernate.hql.FromParser.token(FromParser.java:94)
        at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
        at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
        at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
        at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
        at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
        at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)
        at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1493)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1464)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1454)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1450)


Does anybody knows what I'm doing wrong?

Regards,

Flavio Matiello


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2004 6:01 pm 
Beginner
Beginner

Joined: Tue Nov 11, 2003 4:49 am
Posts: 47
Location: Florence, Italy
Usually this happen when you don't have an import or an alias for your class.
What about them in your mapping/configuration ?
Ciao.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 7:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Full class name
Code:
from com.test.Parameter

_________________
Emmanuel


Top
 Profile  
 
 Post subject: It is correct now.
PostPosted: Mon Feb 02, 2004 8:54 am 
Newbie

Joined: Fri Jan 30, 2004 5:10 pm
Posts: 7
Location: S
[quote="l.masini"]Usually this happen when you don't have an import or an alias for your class.
What about them in your mapping/configuration ?
Ciao.[/quote]

Perfect. I've forgotten to put this file in the hibernate.xml.cfg file. My lack of attention.

Thxs.


Top
 Profile  
 
 Post subject: It worked, but Am I doing it right?
PostPosted: Mon Feb 02, 2004 8:58 am 
Newbie

Joined: Fri Jan 30, 2004 5:10 pm
Posts: 7
Location: S
[quote="emmanuel"]Full class name
[code]from com.test.Parameter[/code][/quote]

It worked without the full class name. It is OK not to use the full class name? I'm asking this to avoid further compatiblity problems on a possible new Hibernate version upgrade.

Regards,

Fl


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 9:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes it should be okay. However somtimes some peoples problems get fixed by using the complete class name, so keep that in mind if you are seraching for errors later.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 9:21 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The full class name is required when several classes have the same name.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.