My database has a column of type DATETIME. What type of Java variable do I use in the EJB?

Nicholas Whitehead

Question continues: [util.Date didn't work so i tried sql.Date and eventually java.sql.Timestamp. But timestamp needs to be formatted in ejbStore to be put in DB and also upon creation of the bean, timestamp must be formatted to be inserted in the db. But i can't format within the ejbCreate method itself. Where is such formatting to take place so that a java variable can be passed to a column of type DATETIME?]

I am not sure why you cannot format in ejbCreate. I assume this is some sort of CMP issue. However, we experienced a similar issue where we needed to reference a database generated sequence in the creation of the entity bean, and the CMP process did not give us access to the generated number in ejbCreate. In this case, we used the ejbPostCreate method which is called directly after ejbCreate and I believe is specifically intended to support operations like yours.

[OK, but the proper type is java.sql.Timestamp, right? -Alex]

See also How do I map a Date/Time field to an Oracle database with CMP?
0 Comments  (click to add your comment)
Comment and Contribute





