I would be very interested in people's recommended ways of using CMP to store dates - or can anyone point me to a chapter of reading info / examples ?
Also, I see that EBJ-QL dosen't support data operators in the WHERE clause for dates (even in 2.1) so how do you add date selection clauses to EJB-QL?
Advice or links greatly appreciated.
I would recommend that you use java.sql.Date as your date data type. Also check your app vendor or mapping docs.
Here is a Finder mapping.
java.util.Collection findActiveByDate(java.sql.Date effectivedate)
SELECT OBJECT(b) FROM MyEJB as b where b.aDate = ?1
For more specific datefunctions like dateadd, datepart, you might have to resort to proprietary app vendor support or use BMP.
You could store the dates as longs (Date.getTime()).
Best regards, Mircea
Thanks for your replies. My dates need to store the time, not just the date. I then also need to be able to do sql where clauses based on date inclusions.
I guess therefore that storing it as a Long might be best, and then passing Longs as where query values for the inclusion values.
Roll on full EJB-QL date support!
java.sql.Date is date and time. The Long is number of milliseconds from 1972. The java.sql.Date will make it easier to query db directly as well, since you can write an sql like this
SELECT * from MyTable where mydate > '4/15/04 1:30:00PM' and mydate < '4/14/04 4:00:00PM'
You can't realy do that with the long millisecond value
SELECT * from MyTable where mydate > '4/15/04 1:30:00PM' and mydate < '4/15/04 4:00:00PM'