persistence@glassfish.java.net

How to reference entity with max value for an attribute

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Mon, 10 Nov 2008 21:47:21 -0500

Dear colleagues,


This is probably a very generic SQL or EJBQL question....

I have a entity class as follows:

@Entity(name = "org.acme.Foo")
@Table(name = "Foo")
@Inheritance(strategy = InheritanceType.JOINED)
public class Foo {

   @id
   String id;

  @version
  int version;

  ...
}


I would like to be able to write a query that reference the latest
version of Foo as identified by the entity that has the largest value
for version. Is such a query possible? If so what would it look like.
Thanks for your help.

-- 
Regards,
Farrukh Najmi
Web: http://www.wellfleetsoftware.com