Rej*_*ran 33 mysql sql database hibernate
我在MySQL时间戳列中插入/更新NULL时观察到意外行为.
请考虑以下陈述.
create table temp(id int, hireDate timestamp default 0);
insert into temp (id) values(1);
insert into temp (id, hireDate) values(2, null);
select * from temp;
id hireDate
-----------------------------
1
2 2012-09-19 10:54:10.0
Run Code Online (Sandbox Code Playgroud)
第一个插入(当hiredate未在SQL中指定时,hireDate null(0)是预期的.
但是,当在SQL中传递显式null时,将插入当前日期时间,这是意外的.为什么会这样?
注意:Hibernate使用第二种类型的插入,因此它成为一个问题.如何将null插入时间戳列?
Jur*_*ens 31
http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html
此外,您可以通过为任何TIMESTAMP列分配NULL值来初始化或更新任何TIMESTAMP列,除非已使用NULL属性定义允许NULL值.
Eri*_*ski 11
创建表:
create table penguins(id int primary key auto_increment, the_time timestamp NULL);
Run Code Online (Sandbox Code Playgroud)
插入一些行:
insert into penguins(the_time) values (now());
insert into penguins(the_time) values (null);
insert into penguins(the_time) values (0);
insert into penguins(the_time) values ('1999-10-10 01:02:03');
Run Code Online (Sandbox Code Playgroud)
哪个印刷品:
select * from penguins
1 2015-01-23 15:40:36
2
3 0000-00-00 00:00:00
4 1999-10-10 01:02:03
Run Code Online (Sandbox Code Playgroud)
the_time使用datatype 调用的列:timestamp在第2行中的值为NULL.