You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Udi <Sa...@gmail.com> on 2009/01/04 09:34:20 UTC
Problem retrieving Timestamp from persistance
Hello,
I have a small application that persist a few fields.
One of the types is timestamp.
When an XLA event is fired, and I try to read the timestamp field, it
returns as an ugly string.
Now, I know that the default for getObject of timestamp type is string, but
is there a way to change the default, so it'll return Date?
Thanx,
Udi
--
View this message in context: http://n2.nabble.com/Problem-retrieving-Timestamp-from-persistance-tp2108549p2108549.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Problem retrieving Timestamp from persistance
Posted by Dinkar Rao <di...@gmail.com>.
Hi,
1. In your table, what is the SQL type of the column corresponding to
the Timestamp field ?
2. What is the run-time type of the returned by m.getObject() for the
Timestamp field ?
I assume MapMessage is your entity class ? And it has a Timestamp
field that is persisted and retreived ? If you can make up an entity
and a sample test that shows the string-like behaviour that would be
helpful.
Thanks,
Dinkar
Re: Problem retrieving Timestamp from persistance
Posted by Udi <Sa...@gmail.com>.
Hey, thanx for the comment, sorry it took me a while..
I can't paste my code, but I can explain better:
I do:
MapMessage m = TopicSubscriber.receive();
for each field in the message:
Object value = m.getObject(SomeIndex);
Now, when the fields are int, long, String etc. it work just fine, and the
object returned are Integer, Long String...
But, when the field type is Timestamp, the getObject() return String by
default. The result is a ugly String which needs to be formatted to Date.
The thing is I don't want to give up on the generic call to getObject().
The optimal thing for me was to be able to replace the default getObject()
considering Date to return Date object.
Is there a way to perform such thing?
Dinkar Rao wrote:
>
> Since java.sql.Timestamp extends java.util.Date, a get() on the
> Timestamp field should already return Date...
>
> ...unless I totally misunderstood your question. Can you paste your
> entity definition and a simple test ?
>
> Thanks,
> Dinkar
>
>
--
View this message in context: http://n2.nabble.com/Problem-retrieving-Timestamp-from-persistance-tp2108549p2151359.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Problem retrieving Timestamp from persistance
Posted by Dinkar Rao <di...@gmail.com>.
Since java.sql.Timestamp extends java.util.Date, a get() on the
Timestamp field should already return Date...
...unless I totally misunderstood your question. Can you paste your
entity definition and a simple test ?
Thanks,
Dinkar