EJB QL How to find most recent date?

Hi all,

I have a trouble here while trying to find most recent date register from my table.

Here goes my finder method:

public Project findLastCreated()throws RemoteException{

String ejbQl ="select max(p.creationDate) from Project p";

Project result = entityManager.createQuery(ejbQl).getSingleResult();

return result;

}

When running this method it gives me an exception because something about timestamp.

The database is MySql and the field "CREATION_DATE" is "DATETIME" type. Anyone can help me? How can I find the most recent date register using EJB QL?

Regards,

Fabricio Braga

[833 byte] By [fabriciobragaa] at [2007-10-2 10:28:04]
# 1

Hi,

try to change it to

import java.util.Date

public Date findLastCreate() throws RemoteException {

// finder

}

You return only the CREATION_DATE field instead of a value object of Project.

dan-ba at 2007-7-13 2:09:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
What came to my mind the moment I clicked on "Post"... doesn't the spec say that finders may only return value objects or collections of these?
dan-ba at 2007-7-13 2:09:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
The finder method returns only one Object.You solutions works fine, thank you very much. I will give you the duke dollars.Regards,Fabricio Braga
fabriciobragaa at 2007-7-13 2:09:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...