0 Replies Latest reply on Aug 25, 2007 2:43 PM by Sebastien Arbogast

    Hibernate 3, MySQL and nullable timestamp

    Sebastien Arbogast Newbie

      I've got an issue with Hibernate 3 hbm2ddl and my MySQL 5.0 database
      One of my entities has a field that is mapped onto a TIMESTAMP column. This field can be null but in MySQL, a TIMESTAMP can only be null if specified in the column declaration. From MySQL documentation:

      TIMESTAMP columns are NOT NULL by default, cannot contain NULL values, and assigning NULL assigns the current timestamp. However, a TIMESTAMP column can be allowed to contain NULL by declaring it with the NULL attribute. In this case, the default value also becomes NULL unless overridden with a DEFAULT clause that specifies a different default value.

      Unfortunately, the following mapping:
      <hibernate-mapping default-cascade="none">
       <class name="com.thalys.opalys.domain.IncidentImpl" table="INCIDENT" dynamic-insert="false" dynamic-update="false">
       <property name="endDate" >
       <column name="END_DATE" not-null="false" unique="false" sql-type="TIMESTAMP"/>
       <type name="org.joda.time.contrib.hibernate.PersistentLocalDate">

      Produces the following CREATE TABLE when hdm2ddl runs:
      create table INCIDENT (
       ) type=InnoDB;

      Did I miss something or is it a bug?