Hibernate Query - Get latest versions by timestamp?
Posted
by Slim
on Stack Overflow
See other posts from Stack Overflow
or by Slim
Published on 2010-05-01T23:38:24Z
Indexed on
2010/05/01
23:47 UTC
Read the original article
Hit count: 177
I have a database that is being used as a sort of version control system. That is, instead of ever updating any rows, I add a new row with the same information. Each row also contains a version
column that is a date timestamp, so the only difference is the new row will have a more recent timestamp.
What I'm having trouble with is writing an efficient hibernate query to return the latest version of these rows. For the sake of example, these are rows in a table called Product
, the timestamped column is version
. There are multiple versions of multiple products in the table. So there may be multiple versions (rows) of ProductA, multiple versions of ProductB, etc. And I would like to grab the latest version of each.
Can I do this in just a single hibernate query?
session.createQuery("select product from Product product where...?");
Or would this require some intermediate steps?
© Stack Overflow or respective owner