persistence@glassfish.java.net

Re: what Java type to use for derby DATE?

From: Pavel Buzek <Pavel.Buzek_at_Sun.COM>
Date: Wed, 08 Feb 2006 16:48:44 -0500

Mitesh,

thanks for this, it works.

May I ask what is the reason why I should use javax.sql.Date as opposed
to java.util.Date? Javadoc of javax.sql.Date says that it allows JDBC to
identify it as DATE, which seems to be solved by TemporalType.DATE. Both
java.util.Date and javax.sql.Date are listed in the persistence spec as
supported basic types. And java.util.Date has the nice feature that it
works with JSF convertors out of the box. But I do not want to miss
something. I am going to use this in NetBeans DB 2 Java code generator
so I want to make sure it generates code that is "right".

Thanks,
-pavel

Mitesh Meswani wrote:
> Hi Pavel,
>
> The DATE type column of Derby should be mapped to java.sql.Date in the
> entity. Currently you are also required to specify the temporal type on
> the property as follows
>
> @Temporal(TemporalType.DATE)
> public Date getDate()
>
> Thanks,
> Mitesh
>
> Pavel Buzek wrote:
>
>> Does anybody happen to know what Java data type would work for Derby
>> DATE type? I have an existing table and need to match its types. To
>> test this I use java.util.Date and use createtables. Derby generates
>> TIMESTAMP. If I tell it to generate DATE using
>> @Column(columnDefinition="DATE") I can read it into java.util.Date but
>> setting a Date value generates:
>>
>> EJB5071: Some remote or transactional roll back exception occurred
>> Local Exception Stack:
>> Exception [TOPLINK-4002] (Oracle TopLink Essentials - 10g release 4
>> (10.1.4.0.0) (Build 060124Dev)):
>> oracle.toplink.essentials.exceptions.DatabaseException
>> Internal Exception: org.apache.derby.client.am.SqlException: Columns
>> of type 'DATE' cannot hold values of type 'TIMESTAMP'. Error Code: -1
>> Call:UPDATE TESDDATEGEN SET FOODATE = {ts '2004-02-25 00:00:00.0'}
>> WHERE (ID = 1)
>> Query:UpdateObjectQuery(foo.TesdDateGen_at_1d2e0bd)
>> at
>> oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:295)
>>
>> at
>> oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:639)
>>
>> at
>> oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:688)
>>
>> at
>> oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:477)
>>
>> etc.
>>
>>
>>
>> Thanks,
>> -pavel