You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by "Schramm, Rich" <ri...@mbari.org> on 2003/05/01 02:14:03 UTC
RE: Timestamp FieldConverter not called on object retreival
Found my problem... I had multiple field descriptors in my Repository, one with TIMESTAMP the other with DATETIME, missed it due to inherited classes... my mistake sorry for the trouble...
Rich Schramm
<field-descriptor
name="startDateTime"
column="startDateTime"
jdbc-type="TIMESTAMP"
conversion="myapp.MyConverter"
/>
-----Original Message-----
From: Schramm, Rich [mailto:rich@mbari.org]
Sent: Wednesday, April 30, 2003 2:28 PM
To: 'OJB Users List'
Subject: Timestamp FieldConverter not called on object retreival
I have a class which I am mapping a java.util.Date field to mssql datetime type column. I first tried using the provide converter (JavaDate2SqlTimestampFieldConversion), and it didnt seem to be called so I tried doing my own.
The converter is being called on object creates but not when objects are retrieved. I dont recieve any error messages. Ive run it in a debugger, and the print.lines and the debugger breakpoints get hit on creates but never on OJL query.
The correct object is returned with a startDateTime being a java.util.Date object so perhaps some other converter is being called???
Im really confused. Any ideas ?
(my application's storage & retrieval worked fine when I dont try and use converter and make the class field a java.sql.Timestamp, but my customer ultimately wants to be able to use java.util.Date)
(also, db-ojb.1.0.RC2 and the ODMG api)
Thanks - Rich Schramm
1) In my class:
protected java.util.Date startDateTime;
public java.util.Date getStartDateTime(){ return startDateTime; }
public void setStartDateTime(java.util.Date dtg){ this.startDateTime = dtg; }
2) In the Repository (TIMESTAMP because mssql server type datetime maps to JDBC(?) type TIMESTAMP )
<field-descriptor
name="startDateTime"
column="startDateTime"
jdbc-type="TIMESTAMP"
conversion="myapp.MyConverter"
/>
2) the converter..(a stripped down & renamed copy of org.apache.ojb.broker.accesslayer.conversions.FieldConversion.JavaDate2SqlTimestampFieldConversion.java)
package myapp;
public class MyConverter implements org.apache.ojb.broker.accesslayer.conversions.FieldConversion
{
public Object javaToSql(Object source)
{
System.out.println("in converter javaToSql");
if (source instanceof java.util.Date)
{
return new java.sql.Timestamp( ((java.util.Date) source).getTime());
}
else { return source; }
}
public Object sqlToJava(Object source)
{
System.out.println("in converter sqlToJava");
if (source instanceof java.sql.Timestamp)
{
return new java.util.Date( ((java.sql.Timestamp) source).getTime());
// i think i need to modify this later to preserve seconds.. but maybe not
// if my problem appears to be this is not even being called..
}
else { return source; }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org