-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need help with HQL query
PostPosted: Sun Jan 30, 2011 5:32 pm 
Newbie

Joined: Mon Sep 13, 2010 1:08 pm
Posts: 5
Hi people, I have a simple class, called Person, as follows:
Code:
public class Person {
    private Integer id;
    private String name;
    private List<PersonState> states;
    ...
}

And each PersonState is defined like:
Code:
public class PersonState {
    private Integer id;
    private State state;
    private Date date;
    ...
}

And State is a simple class, containing only an id and name, and I have all the mapping files configured and working.

I want to get those Persons whose last PersonState (based on it's date) has an State with id = 5 (for instance), so what would be the HQL query like? Thanks!

_________________
Joaquin L. Robles
reweb
www.reweb.com.ar


Top
 Profile  
 
 Post subject: Re: Need help with HQL query
PostPosted: Mon Jan 31, 2011 5:28 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
You need to use a group by / having clause.
Something like that: ... group by ... having date = max(date)


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