Wednesday, April 9, 2014

MySQL 5.6: Fixing awkward TIMESTAMP behaviours - old

MySQL treats timestamp column in a special way.
If the column is not set with null attribute, it considers it as not null. And when timestamp column is set to not null, it sets the default value for this field to current time stamp if the value is not set during insert or update.




 Now recreate the table using the keyword null for the timestamp column.



create table shift (
        id bigint not null auto_increment,
        rec_start_date TIMESTAMP null,
        rec_end_date TIMESTAMP null,
        primary key (id)
    ) ;

ref:
http://guilhembichot.blogspot.in/2013/02/fixing-awkward-timestamp-behaviors.html

http://shankargopal.blogspot.in/2013/03/mysql-566-timestamp-columns-and-default.html

Hibernate Issue with mySQL 5.6

Hibernate tools doesn't add "null" attribute to the columns set explicitly as not-null = false;

    true
    true
   


If hbm2java tools is used to generate the sql, it doesn't add null attribute to column. We need to add an update script on top of existing tables to update the timestamp column to have null value.