JPQL Query using max on a date field

Well I guess the moderator didn't bother to read the edit that moved the answer up: comment from questioner on intent of query:

"I have a table that conains a list of data elements (id, message(string), siteId (string), createdDate (Timestamp). What I need to do is select by the siteId, then find the record in that group with the most recent createdDate."

Solution:

Query query = entityManagerReference.createQuery(
"SELECT msg FROM ImportedMessage msg " 
+ "WHERE msg.siteId = :siteId ORDER BY msg.createDate desc");

query.setParameter("siteId", 12345);
query.setMaxResults(1);

Tags:

Jpa

Jpql