You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Mike Pearce <mi...@studioelectrica.com> on 2003/07/08 01:09:46 UTC

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


Re: Timestamp brokering in HSQL, et al (and OJB XDoclet)

Posted by Mike Pearce <mi...@studioelectrica.com>.
> > Shouldn't the FieldConversion attribute be used only for
> "non-standard"
> > configurations.
>
> but what is the definition of non-standard?
> Is java.util.Date --> java.sql.Date standard?
> Does the  JDBC 2.0 specification specify a
> mapping for java.util.Date?

Good point.  Nothing like the definition of what is "standard" and not. :)
JDBC does not discuss java.util.Date, to my knowledge.  So i would now agree
that OJB does handle it correctly.  Thanks for the clarification.

And, the OJB XDoclet does seem to hide this from the user by automatically
adding the "conversion" attribute to field-descriptor when the type of the
Object's field is a java.util.Date.  Unfortunately, if you set the
"jdbc-type" XDoclet attribute, the "conversion" attribute will not be added
automatically.

-mike


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


Re: Timestamp brokering in HSQL, et al

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi again,

----- Original Message -----
From: "Mike Pearce" <mi...@studioelectrica.com>
To: "OJB Developers List" <oj...@db.apache.org>
Sent: Tuesday, July 08, 2003 1:35 AM
Subject: Re: Timestamp brokering in HSQL, et al


> Shouldn't the FieldConversion attribute be used only for
"non-standard"
> configurations.

but what is the definition of non-standard?
Is java.util.Date --> java.sql.Date standard?
Does the  JDBC 2.0 specification specify a
mapping for java.util.Date?


> I am creating a new database with OJB/Torque.  Under this
> situation, the field conversions should already be correct - which
they are
> not. :)
>
> BTW, should this have been sent to the users' list?
>

if you insist your conversion is a standard conversion
--> dev list
else
--> user list
;-)

regards,
Armin

> -mike
>
> ----- Original Message -----
> From: "Armin Waibel" <ar...@code-au-lait.de>
> To: "OJB Developers List" <oj...@db.apache.org>
> Sent: Monday, July 07, 2003 4:16 PM
> Subject: Re: Timestamp brokering in HSQL, et al
>
>
> > 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" <mi...@studioelectrica.com>
> > To: <oj...@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
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> 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


Re: Timestamp brokering in HSQL, et al

Posted by Mike Pearce <mi...@studioelectrica.com>.
Shouldn't the FieldConversion attribute be used only for "non-standard"
configurations.  I am creating a new database with OJB/Torque.  Under this
situation, the field conversions should already be correct - which they are
not. :)

BTW, should this have been sent to the users' list?

-mike

----- Original Message ----- 
From: "Armin Waibel" <ar...@code-au-lait.de>
To: "OJB Developers List" <oj...@db.apache.org>
Sent: Monday, July 07, 2003 4:16 PM
Subject: Re: Timestamp brokering in HSQL, et al


> 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" <mi...@studioelectrica.com>
> To: <oj...@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
>
>
>


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


Re: Timestamp brokering in HSQL, et al

Posted by Armin Waibel <ar...@code-au-lait.de>.
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" <mi...@studioelectrica.com>
To: <oj...@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