You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Shinkan <sh...@gmail.com> on 2008/08/07 12:31:43 UTC

SQL TIMESTAMP and Torque java.util.Date mapping.

Hi again there !

I have a TIMESTAMP type column in a schema, and the Torque maps it to
java.util.Date, which is really convenient most of the time.
BUT, I would like to check for this column nullity, SQL point-of-view.
That's to say, I have to check that this field, let's call it "expires", is
NULL Timestamp (00-00-0000 00:00:00).
Trying to compare expires against new Date(0) fails as new Date(0) gives
(and that's obvious), the first UNIX timestamp date.
I can use New Date(int, int, int, int, int, int) BUT it is deprecated, and I
really would like to avoid this.

So, how can I build a Criteria to check if my field "expires" from table
"test" is NULL timestamp (00-00-0000 00:00:00) ?
timeCrit.add( TestPeer.EXPIRES, ?????????);

Thanks in advance !

-- 
Pierre.
Some people, when confronted with a problem, think "I know, I'll use XML".
Now they have two problems. -- Jamie Zawinski / James Robertson

Re: SQL TIMESTAMP and Torque java.util.Date mapping.

Posted by Shinkan <sh...@gmail.com>.
Really thanks for your support.

Derby doc doesn't say much about this, but it seems that I have to specify
default="CURRENT_TIMESTAMP" to make them filled.
In fact the behavior is good, by not adding "default" clause, and adding
required = "false", I expect my DB to init it to NULL or equivalent.

Then, don't worry as I just discovered problem didn't come from Derby or
Torche, but from me using Java :D
I store UNIX timestamps in XML files (they are in SECONDS), then I try to
build java.util.Date with Long parse of these timestamp ... BUT, Java
expects milliseconds ...
As I stored my results in DB, all my data dates were buggy.


-- 
Pierre.
Some people, when confronted with a problem, think "I know, I'll use XML".
Now they have two problems. -- Jamie Zawinski / James Robertson

Re: SQL TIMESTAMP and Torque java.util.Date mapping.

Posted by Thomas Vandahl <tv...@apache.org>.
Shinkan wrote:
> Maybe that is because my schema doesn't NULL the value correctly ? Here is
> the column definition :
> <column name="expires"
>       type="TIMESTAMP"
>       required="false" />
> And the generated SQL:
> expiration TIMESTAMP,

That looks ok to me. Based on this definition

>> criteria.add(TestPeer.EXPIRES, (Object) null, Criteria.ISNULL)

seems to be the right way to check for a null value. Unless Derby is 
doing something strange with TIMESTAMP columns by itself - like, for 
example, MySQL which would insert the current timestamp in such a column.

What does Derbys documentation say about TIMESTAMP columns?

Bye, Thomas.

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


Re: SQL TIMESTAMP and Torque java.util.Date mapping.

Posted by Shinkan <sh...@gmail.com>.
Hi !

Nope, I tried it before, but it seems that "IS NULL" is different from "=
{ts '00-00....}".
By the way, the deprecated new Date(0, 0, 0, 0, 0, 0) corresponds to "{ts
'1899-12-31 00:00:00.0'}" on my env.
I could also build a custome crit like dateCrit.add(TestPeer.EXPIRES,
(Object)"={ts '0000-00-00 00:00:00.0'}", Criteria.CUSTOM) but I don't think
this is generic enough ... maybe some databases work with another timestamp
format (I use Derby here).

Maybe that is because my schema doesn't NULL the value correctly ? Here is
the column definition :
<column name="expires"
      type="TIMESTAMP"
      required="false" />
And the generated SQL:
expiration TIMESTAMP,

Any idea ?


On Thu, Aug 7, 2008 at 12:38, Hidde Boonstra [Us Media] <
hidde.boonstra@usmedia.nl> wrote:

> Hi,
>
> criteria.add(TestPeer.EXPIRES, (Object) null, Criteria.ISNULL)
>
> doesn't work?
>
> Regards,
>
> Shinkan wrote:
>
>> Hi again there !
>>
>> I have a TIMESTAMP type column in a schema, and the Torque maps it to
>> java.util.Date, which is really convenient most of the time.
>> BUT, I would like to check for this column nullity, SQL point-of-view.
>> That's to say, I have to check that this field, let's call it "expires",
>> is
>> NULL Timestamp (00-00-0000 00:00:00).
>> Trying to compare expires against new Date(0) fails as new Date(0) gives
>> (and that's obvious), the first UNIX timestamp date.
>> I can use New Date(int, int, int, int, int, int) BUT it is deprecated, and
>> I
>> really would like to avoid this.
>>
>> So, how can I build a Criteria to check if my field "expires" from table
>> "test" is NULL timestamp (00-00-0000 00:00:00) ?
>> timeCrit.add( TestPeer.EXPIRES, ?????????);
>>
>> Thanks in advance !
>>
>>
> --
> Hidde Boonstra
> Us Media B.V.
> Stadhouderskade 115
> 1073 AX Amsterdam
>
> t: 020 428 68 68
> f: 020 470 69 05
> www.usmedia.nl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>


-- 
Pierre.
Some people, when confronted with a problem, think "I know, I'll use XML".
Now they have two problems. -- Jamie Zawinski / James Robertson

Re: SQL TIMESTAMP and Torque java.util.Date mapping.

Posted by "Hidde Boonstra [Us Media]" <hi...@usmedia.nl>.
Hi,

criteria.add(TestPeer.EXPIRES, (Object) null, Criteria.ISNULL)

doesn't work?

Regards,

Shinkan wrote:
> Hi again there !
> 
> I have a TIMESTAMP type column in a schema, and the Torque maps it to
> java.util.Date, which is really convenient most of the time.
> BUT, I would like to check for this column nullity, SQL point-of-view.
> That's to say, I have to check that this field, let's call it "expires", is
> NULL Timestamp (00-00-0000 00:00:00).
> Trying to compare expires against new Date(0) fails as new Date(0) gives
> (and that's obvious), the first UNIX timestamp date.
> I can use New Date(int, int, int, int, int, int) BUT it is deprecated, and I
> really would like to avoid this.
> 
> So, how can I build a Criteria to check if my field "expires" from table
> "test" is NULL timestamp (00-00-0000 00:00:00) ?
> timeCrit.add( TestPeer.EXPIRES, ?????????);
> 
> Thanks in advance !
> 

-- 
Hidde Boonstra
Us Media B.V.
Stadhouderskade 115
1073 AX Amsterdam

t: 020 428 68 68
f: 020 470 69 05
www.usmedia.nl

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