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.
<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"> </type> </property> <!--...--> </class> </hibernate-mapping>
create table INCIDENT ( --... END_DATE TIMESTAMP, --... ) type=InnoDB;