-->
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: Using Restrictions to compare two columns
PostPosted: Mon Sep 27, 2010 10:06 pm 
Newbie

Joined: Tue Jun 15, 2010 1:00 pm
Posts: 3
Location: Anaheim, California
Lets say for example I have an object Parent with a spouse:
Code:
class Parent {
    String name;
    int age;
    Parent spouse;
}

I'd like to have a query that gets the oldest Parents per couple:
Code:
...add(Restrictions.gt("age", ???spouse.age???));

I can't find a way to pass anything but a hard value in as the second argument. I could right my own implementation of the Criterion interface, but that seems silly for what seems like a simple query that others must have done.

Even some help with a much more simple example would probably point me down the right path.
How to get Things where valueA is greater than valueB;
Code:
class Thing {
    int valueA;
    int valueB;
}

...add(Restrictions.gt("valueA", ???valueB???));

Again, I'm not sure how to pass in the second argument since I need to reference another column.

I appreciate the help while I continue to look through the source for a solution.
- Chris


Top
 Profile  
 
 Post subject: Re: Using Restrictions to compare two columns
PostPosted: Tue Sep 28, 2010 2:25 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Restrictions.geProperty("valueA", "valueB") or gtProperty, ltProperty, leProperty, whatever you need.


Top
 Profile  
 
 Post subject: Re: Using Restrictions to compare two columns
PostPosted: Tue Sep 28, 2010 6:44 am 
Newbie

Joined: Tue Jun 15, 2010 1:00 pm
Posts: 3
Location: Anaheim, California
Thanks for pointing out the obvious to me. I immediately started digging deeper in the wrong place trying to figure out how SimpleExpression could be modified to support property names. I glossed right over the now obvious PropertyExpression.

Again, thanks.


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.