-->
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: problem with criteria / expression
PostPosted: Thu Nov 06, 2003 8:52 am 
Newbie

Joined: Thu Nov 06, 2003 8:32 am
Posts: 5
I have a mapping many to one fairly standard I think a "titles" class with a genre property which is an instance of a genre class

<many-to-one name="genre" class="my.domain.Genres" column="genreid"/>

I can do this HQL successfully:
"select titles.genre.genreid from Titles as titles"

BUT

I am using the criteria api to build dynamic queries, and when I attempt to add
crit.add(Expression.eq("genre.genreid", x));

I get an exception:
net.sf.hibernate.QueryException: unresolved property: genre.genreid [null]

any advice?

thank you,
Al


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 9:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
crit.createCriteria("genre").add(Expression.eq("genreid", x));

Hibernate 2.1.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 10:14 am 
Newbie

Joined: Thu Nov 06, 2003 8:32 am
Posts: 5
Thank you

OK, but I want to create a criteria based on two classes now
i.e where titleName=x and genreid=y
(Titles->titleName, Genre->genreid)

if I have to create two criteria, how can I "and" the two together, because I only way that I can see is to do
Criteria crit1 = ses.createCriteria(Titles.class);
crit.add...
crit.list();
Criteria crit2 = ses.createCriteria(Genre.class);
crit.add...
crit.list();

Can I feed the results of one list into the second criteria?

cheers, al


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 10:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You misunderstood. It helps to read the documentation.

There are two methods named createCriteria(), one on the Session intfc, one on the Criteria intfc. Ther have completely diff signatures.


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.