-->
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.  [ 8 posts ] 
Author Message
 Post subject: Querying on nested properties
PostPosted: Wed Oct 29, 2003 10:51 am 
Newbie

Joined: Wed Oct 29, 2003 10:47 am
Posts: 7
Location: Waukesha, WI
Hello,

I'm relatively new to Hibernate (am actually porting over / abstracting much of my Castor-based code), and i've run into a snag. In Castor, you can query on nested properties such as "where answer.question.survey.id = 1". This dot notation works one level deep with Hibernate (such as "where survey.id = 1"), but seems to die when we go one level deeper.

Is there a way to query on nested properties using the Expression builder?

ex: Expression.eq("answer.question.survey.id", new Long(1));

Any help would be greatly appreciated,
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 10:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Are you talking about HQL, or about the Criteria API?

In HQL, you can use path expressions to navigate joins.

In the Criteria API, you cannot (they may only navigate component paths) and this is probably a Good Thing.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you are just asking how to do joins in the Criteria API, use Criteria.createCriteria(String), or Criteria.createAlias(String, String).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 11:21 am 
Newbie

Joined: Wed Oct 29, 2003 10:47 am
Posts: 7
Location: Waukesha, WI
I don't see Criteria.createCriteria(String) or Criteria.createAlias(String, String) in the Hibernate 2.0 API... am I missing it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 11:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate 2.1 beta 4


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 11:46 am 
Newbie

Joined: Wed Oct 29, 2003 10:47 am
Posts: 7
Location: Waukesha, WI
Excellent...

Keep up the great work on your fantastic product!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 11:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Welcome...

I did the same migration (from Castor to Hibernate) about a year ago. You will not regret it. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 12:11 pm 
Newbie

Joined: Wed Oct 29, 2003 10:47 am
Posts: 7
Location: Waukesha, WI
Well, i'm trying to keep my apps "persistence layer agnostic" by abstracting out all reading/writing functionality... The problem is that there are so many features that Hibernate has that Castor doesn't have, that makes me wonder if it's even worth trying to treat the two as "equals".

Question:
The API docs for Hibernate 2.1 beta 4 are a bit sparse regarding Criteria.createAlias(String, String) and Criteria.createCriteria(String). If I wanted to implement a join (nested property lookup), what would the code look like?

For example, what would I translate something like:
Expression.eq("survey.question.answer.id", new Long(1)) to using Criteria.createAlias or createCriteria?

My interface for my "generic" querying mechanism has a function:
addWhereClause(String property, String comparison, Object value)

This works pretty directly in Castor. I have to translate these into the appropriate Expression.eq...etc statements in Hibernate (no big deal). I really don't want to use HQL, since it's not as OO as the Criteria API. I wrote a translator for Castor's OQL. It was a ton of work, and I don't want to have to go through that again :)


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