users@glassfish.java.net

Re: A simple JPA query made difficult with MAX ?

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Tue, 23 Sep 2008 15:53:13 +0200

Maybe something like this:

@SuppressWarnings("unchecked")
List<Record> resultList = em.createQuery(
"SELECT r " +
"FROM Record r " +
"ORDER BY r.id DESC")
.setMaxResults(1)
.getResultList();

Record result = result.isEmty()
  ? null
  : resultList.get(0);

Regards,
Witold Szczerba

2008/9/23 <glassfish_at_javadesktop.org>:
> Thank you very much Chris. I had taken to creating a native sql query and mapping the result, however your method is much more elegant!
>
> Regards,
> John
> [Message sent by forum member 'johnnydh' (johnnydh)]
>
> http://forums.java.net/jive/thread.jspa?messageID=300979
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>