-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria query and components (value types)
PostPosted: Fri Jun 20, 2008 6:30 am 
Newbie

Joined: Mon Aug 23, 2004 7:54 am
Posts: 15
Hello

I have the following mapping:

Code:
<class name="User" table="USER">
     ...
     <one-to-one name="person" class="Person"/>
</class>

<class name="Person" table="PERSON">
      ...
      <component name="address" class="Address">
           ...
           <property name="city" type="string" column="CITY"/>
      </component>
</class>


I try to build a Criteria query knowing the city:

Code:
DetachedCriteria detachedCriteria = DetachedCriteria
         .forClass(User.class)                  
         .createAlias("person", "p")
         .createAlias("p.address", "a")
                        .add(Restrictions.like("a.city", myCity);


The error I get is:
could not resolve property: address of: Person

What am I doing wrong?


Top
 Profile  
 
 Post subject: answer
PostPosted: Fri Jun 20, 2008 11:03 am 
Newbie

Joined: Mon Aug 23, 2004 7:54 am
Posts: 15
Very stupid question I guess... createAlias it's about joins and I have components here.
I should have done Restrictions.like("p.address.city", myCity)
and eliminate createAlias("p.address", "a").


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 10:11 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Restrictions is definitely the way to go.

Don't feel bad about stupid questions. There's probably thousands of very smart people out there asking themselves the very same thing!

By the way, here's a very simple and straight forward tutorial on how to use the Hibernate Criteria API:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=09howtousethecriteriaapi

You might find it helpful.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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