views:

44

answers:

2

I have a table like so:

mysql> show create table foo;
CREATE TABLE foo
(
    network bigint NOT NULL,
    activeDate datetime NULL default '0000-00-00 00:00:00',
    ...
)

In the domain object, FooVO the activeDate member is annotated as Temporal. If I don't set activeDate to a valid Date instance, a new record is inserted with NULLs. I want the default value to take effect if I don't set the activeDate member. Thanks.

A: 

Aren't you supposed to use NOT NULL for the activeDate column if you want the default to get set?

CREATE TABLE foo
(
    network bigint NOT NULL,
    activeDate datetime NOT NULL default '0000-00-00 00:00:00',
    ...
)
Pascal Thivent
A: 

If you are using EclipseLink then you can specify @ReturnInsert(returnOnly=true) to do this. Unfortunately if you are still using Toplink the only way I have found to deal with this issue is to not specify the @Temporal on your date column and write wrapper methods to convert back and forth from Date to String.

perilandmishap