Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

Q: Howto set TIMESTAMP column to null?

Dirk Brenckmann

2008-07-02

Replies: Find Java Web Hosting

Author LoginPost Reply
Database: mysql 4.1
Geronimo 2.0.1

Hi there,

I'm using a database with timestamp columns that can be null. Using SQL syntax, null enties can be set by either not setting the field when creating a row, or by explictly setting it to '0000-00-00 00:00:00'.

This lead me to some amazing discoveries :-)

Merging the Bean using a null value results in a database column value equals to "NOW()" (GNARF!)
java.sql.Timestamp.valueOf( "0000-00-00 00:00:00" ); results in an OutOfMemoryException

--- code ---

  /**
  * Returns the "valid to" timestamp, which specifies the date/time when entitys
  * data becomes invalid. A value of null or '0000-00-00 00:00:00' means, the entity
  * never becomes invalid.
  *
  * @return the "valid to" timestamp of the entity.
  */
  @Column( name = "validTo",
        columnDefinition = "timestamp default '0000-00-00 00:00:00'",
        nullable = true, insertable = true, updatable = true )
  // @Temporal( TemporalType.TIMESTAMP )
  public java.sql.Timestamp getValidTo() {
    return this.validTo;
  }
--- code ---

Switching to java.langString (as return type) results in an OutOfMemoryException (My guess is a convertion: see Timestamp)

The @Temporal annotation was removed, due to what ? You are right - due to an OutOfMemoryException :-)


Please be aware that changing the database (a few GB data) to not use null/'0000-00-00 00:00:00' values is no option at all.

Any ideas how to get this working?
Tyvm in advance.
--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@(protected)
©2008 gg3721.com - Jax Systems, LLC, U.S.A.