-->
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 and fetchmode?
PostPosted: Wed Mar 12, 2008 8:29 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.5.ga</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.1.ga</version>
</dependency>


Mapping documents:
JPA
Code between sessionFactory.openSession() and session.close():
Spring handled
Full stack trace of any exception that occurs:

Name and version of the database you are using:
mysql 5.5
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hi I have following structure:

A Cat has Kittens(collection) and Kitten has fleas(collection) :)

A flea has a property called bloodType.

Now I only want cats that has kittens with fleas that has bloodType a. How do I do this?

I tried this:
Criteria criteria = getHibernateSession().createCriteria(Cat.class);
criteria = criteria.setFetchMode("kittens", FetchMode.SELECT)
.setFetchMode("fleas", FetchMode.SELECT).add(
Restrictions.in("bloodType", searchParameters
.getbloodTypes()));

But I get this error:

org.hibernate.QueryException: could not resolve property: bloodType of: cat


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 12:14 pm 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
Have explained my self wrongly. This should be possible right? I you need me to explain another please say so.

Or if I am posting in the wrong forum etc...

regards Nino


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 3:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you need to use createAlias.
Check the reference doc

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 9:48 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
emmanuel wrote:
you need to use createAlias.
Check the reference doc


true. Thanks. For those who could be interested the solution are this:

criteria.createAlias("kittens", "ts").createAlias(
"ts.fleas", "tst").add(
Restrictions.in("tst.bloodType", searchParameters
.getBloodTypes()));


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.