db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Armin Waibel" <ar...@code-au-lait.de>
Subject Re: Timestamp brokering in HSQL, et al
Date Mon, 07 Jul 2003 23:16:34 GMT
Hi Mike,

I think the better way is to use a
FieldConversion (attribute of field-descriptor)
for your field. e.g.
org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDateFieldConve
rsion

regards,
Armin

----- Original Message -----
From: "Mike Pearce" <mike@studioelectrica.com>
To: <ojb-dev@db.apache.org>
Sent: Tuesday, July 08, 2003 1:09 AM
Subject: Timestamp brokering in HSQL, et al


> When trying to do a simple store of a Persistent Object with a
> java.util.Date field (represented as a TIMESTAMP column in the HSQL
> database), i get an exception that arises from HSQL's inability to
convert
> the java.util.Date to a java.sql.Timestamp (see stacktrace below).  It
> appears that the HSQLDB driver does not accept java.util.Date's as a
> parameter to the PreparedStatement.setObject() method when the type is
> Types.TIMESTAMP (and probably Types.TIME and Types.DATE).
>
> To correct the error, I modified the
> PlatformDefaultImpl.setObjectForStatement() method to test for the
case of a
> java.util.Date, thinking that this problem could also show up with
other
> JDBC drivers:
>         else if (value instanceof java.util.Date)
>         {
>             // convert java.util.Date objects to the java.sql
equivalent
>             if (Types.DATE == sqlType && ! (value instanceof
java.sql.Date))
>             {
>                 value = new java.sql.Date(((java.util.Date)
> value).getTime());
>             }
>             else if (Types.TIMESTAMP == sqlType && ! (value instanceof
> java.sql.Timestamp))
>             {
>                 value = new java.sql.Timestamp(((java.util.Date)
> value).getTime());
>             }
>             else if (Types.TIME == sqlType && ! (value instanceof
> java.sql.Time))
>             {
>                 value = new java.sql.Time(((java.util.Date)
> value).getTime());
>             }
>
>             ps.setObject(index, value, sqlType);
>         }
>
>
> Stack Trace:
> java.lang.IllegalArgumentException: Timestamp format must be
yyyy-mm-dd
> hh:mm:ss
> .fffffffff
>         at java.sql.Timestamp.valueOf(Timestamp.java:188)
>         at
org.hsqldb.lib.HsqlDateTime.timestampValue(HsqlDateTime.java:82)
>         at org.hsqldb.Column.convertString(Column.java:1292)
>         at org.hsqldb.Column.convertObject(Column.java:1239)
>         at
> org.hsqldb.jdbcPreparedStatement.setObject(jdbcPreparedStatement.java
> :1137)
>         at
> org.apache.ojb.broker.platforms.PlatformDefaultImpl.setObjectForState
> ment(Unknown Source)
>         at
> org.apache.ojb.broker.accesslayer.StatementManager.bindInsert(Unknown
>  Source)
>         at
> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(Unknow
> n Source)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown So
> urce)
>         at
org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown
> Source
> )
>         at
org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown
> Source
> )
>         at
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown
> Source)
>         at
> org.apache.ojb.jdori.sql.OjbStoreManager.insert(OjbStoreManager.java:
>
> -mike
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message