-->
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.  [ 1 post ] 
Author Message
 Post subject: LEFT JOIN Problem or how to find the latest entry for each
PostPosted: Wed Jan 18, 2012 9:56 am 
Newbie

Joined: Wed Jan 18, 2012 9:29 am
Posts: 1
Hi,

my class (and table):

Code:
@Entity
public class ProcessState {

  @Id
  private int id;

  private int processId;

  private Date date;

  private String state;

...
}


at each time the state of a process changes a new entry with current time and state is stored in db.

Now the problem is to get the states for a list of processIds to a given date. E.g. for each processId the entry with the greatest date less than the given date.

in sql i would do this with a left join:
Code:
  SELECT *
      FROM ProcessState ps
          LEFT JOIN ProcessState ps2
            ON ps.processId = ps2.processId
              AND ps.date < ps2.date
      WHERE ps2.processId IS NULL
        AND ps.processId in ([list of processIds])
        AND ps.date < [the given date];


But i can't figure out how to do this in a hibernate Criteria which i would prefer nor in HQL.


Regards,
Volker


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.