Hi,
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.
Many thanks,
Andy
-
How best to persist / model dates with CMP? (5 messages)
- Posted by: Andrew Steady
- Posted on: April 14 2004 05:39 EDT
Threaded Messages (5)
- How best to persist / model dates with CMP? by Michael Malkinzon on April 14 2004 11:16 EDT
- How best to persist / model dates with CMP? by Mircea Crisan on April 15 2004 02:26 EDT
- How best to persist / model dates with CMP? by Andrew Steady on April 16 2004 07:14 EDT
- java.sql.Date is date and time by Michael Malkinzon on April 16 2004 11:21 EDT
- reviise sql by Michael Malkinzon on April 16 2004 11:22 EDT
- java.sql.Date is date and time by Michael Malkinzon on April 16 2004 11:21 EDT
-
How best to persist / model dates with CMP?[ Go to top ]
- Posted by: Michael Malkinzon
- Posted on: April 14 2004 11:16 EDT
- in response to Andrew Steady
Andrew,
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)
<ejb-ql>
SELECT OBJECT(b) FROM MyEJB as b where b.aDate = ?1
</ejb-ql>
For more specific datefunctions like dateadd, datepart, you might have to resort to proprietary app vendor support or use BMP. -
How best to persist / model dates with CMP?[ Go to top ]
- Posted by: Mircea Crisan
- Posted on: April 15 2004 02:26 EDT
- in response to Andrew Steady
Hi,
You could store the dates as longs (Date.getTime()).
Best regards, Mircea -
How best to persist / model dates with CMP?[ Go to top ]
- Posted by: Andrew Steady
- Posted on: April 16 2004 07:14 EDT
- in response to Andrew Steady
Hi guys,
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!
Thanks,
Andy -
java.sql.Date is date and time[ Go to top ]
- Posted by: Michael Malkinzon
- Posted on: April 16 2004 11:21 EDT
- in response to Andrew Steady
Andrew
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
Goodluck
Mike -
reviise sql[ Go to top ]
- Posted by: Michael Malkinzon
- Posted on: April 16 2004 11:22 EDT
- in response to Michael Malkinzon
SELECT * from MyTable where mydate > '4/15/04 1:30:00PM' and mydate < '4/15/04 4:00:00PM'