[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ojb-user
Subject:    RE: OBJ 1.0 RC6: DB2 & Autoincrement -> Date Conversion problem
From:       "Gelhar, Wallace Joseph" <GELHARWJ () uwec ! edu>
Date:       2004-05-27 20:46:30
Message-ID: FEBBF51AFF7B8B4B8A2F32F6E63092AEF84314 () COKE ! uwec ! edu
[Download RAW message or body]

TIMESTAMP maps to a java.sql.Timestamp as noted in the standard jdbc
mapping types found 
 at http://db.apache.org/ojb/jdbc-types.html

This means that if you use a java.util.Date in your object, you must
define a field conversion to convert to / from Date and Timestamp such
as 

  <field-descriptor
    name="created"
    column="created"
    jdbc-type="TIMESTAMP"
 
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTi
mestampFieldConversion"
  />

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Sebastian
Sent: Thursday, May 27, 2004 3:32 PM
To: ojb-user@db.apache.org
Subject: Re: OBJ 1.0 RC6: DB2 & Autoincrement -> Date Conversion problem


Basically I want DB2 to do the incrementation, therefor I try to get 
SequenceManagerNativeImpl running. I just discovered that I have 
misinterpreted the error message and that it doesn't relate to the 
autoincrement. Instead it looks like a java.util.Date conversion
problem.

I turned on SQL statement debugging in OJB and that shows:
[org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: 
SQL:INSERT INTO USER_TO_COURSE 
(created,status,status_msg,status_date,action) VALUES (?,?,?,?,?)

Then I launched my app in debug mode and found out that the exception is

thrown in the setObjectForStatement method of the PlatformDefaultImpl 
when it tries to call ps.setObject(index, value, sqlType). index = 1
value = (Date) Thu May 27 21:46:53 CEST 2004 sqlType = 93

So when the assigning the value for the created column in the 
preparedStatement the exception is thrown.

The created property of the action class looks like this: private
java.util.Date created = new java.util.Date();

The field mapping like this:
     <field-descriptor
         name="created"
         column="created"
         jdbc-type="TIMESTAMP"
         access="readwrite"
         nullable="false"
     >

The sql for the created column is:
CREATED TIMESTAMP NOT NULL WITH DEFAULT CURRENT TIMESTAMP

Any ideas what's wrong here? Is java.util.Date not supported by OJB?

Pedro Salgado wrote:
>   Aren't you specifying on the SQL for the table to use a native 
> sequence manager implementation?
> 
>   It seems you are trying to use two sequence managers: one provided 
> by OJB (gets max and then incrementes on each insert) and one using 
> the db native.
> 
>   Check http://db.apache.org/ojb/howto-use-db-sequences.html and 
> http://db.apache.org/ojb/sequencemanager.html
> 
>   or try using just
> ID BIGINT NOT NULL
>   and see what happens :)
> 
> Pedro Salgado
> 
> On 04/05/27 19:12, "Sebastian" <nospam_st@gmx.net> wrote:
> 
> 
>>Hi,
>>
>>I'm trying to store objects (using PB) in a DB2 table where 
>>autoincrement is defined for the id column and I don't get it working.
>>
>>This is the SQL I used to create the table:
>>CREATE TABLE ACTION
>>(
>> ID BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, 
>>INCREMENT BY 1, NO CACHE),
>>
>> ... other fields ...
>>
>> PRIMARY KEY (ID)
>>);
>>
>>This is the OBJ Mapping I use for the object: <field-descriptor
>>   name="id"
>>   column="id"
>>   jdbc-type="BIGINT"
>>   primarykey="true"
>>   nullable="false"
>>   access="readonly"
>>   autoincrement="true"
>>
>>This is my class:
>>public class Action
>>{
>> private long id;
>>
>> ... other properties ...
>>}
>>
>>When I use this sequence manager:
>><sequence-manager className= 
>>"org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl"/>
>>then I get:
>>SQL failure while insert object data for class Action, PK of the given

>>object is [ id=-2], object was Action@ef137d, exception message is 
>>[[IBM][JDBC Driver] CLI0613E  Program type out of range. 
>>SQLSTATE=S1003]
>>
>>When I use this sequence manager:
>><sequence-manager className= 
>>"org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
>> <attribute attribute-name="autoNaming" attribute-value="true"/> 
>></sequence-manager> then I get:
>>SQL failure while insert object data for class Action, PK of the given
>>object is [ id=22], object was Action@1fddc31, exception message is
>>[[IBM][JDBC Driver] CLI0613E  Program type out of range.
SQLSTATE=S1003]
>>
>>=> in this on every try the [ id=..] is incremented in the error 
>>message.
>>
>>When I try to insert a record via SQL and do not specify the ID column

>>it works fine.
>>
>>Any ideas or suggestions?
>>
>>Thanks in advance,
>>Sebastian
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org


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


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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic