A simple JPA query made difficult with MAX ?
Having spent all my life utilising Google to answer my questions, I have come across a problem for which I can find no answer and yet it seems so obvious that I can not understand why! If anyone can help, I would appreciate it enormously...
I have an entity Record with a composite primary key consisting of Id and VersionNumber. I need to create a query in JPA which will return the latest Record i.e. highest Id and VersionNumber, in the most elegant way possible.
If this were SQL, I would select max(Id) AS ID, max(versionNumber) AS versionNumber and then group the rest of the fields. I would like to recreate something similar in JPA which returns a simple clean instance (or List) of Record(s).
Can anyone help?