Hibernate 映射不允许空时间戳
我正在开发一个基于 Web 的应用程序,使用 spring-hibernate 组合和 Mysql 作为数据库。我观察到 hibernate 映射存在 1 个问题,即当类型为时间戳时,它不允许我设置 null。这是为了更好地理解的代码片段
我的议程是 - 我想允许用户为 endTime 输入空值,而不是为 stTime 输入空值。
schedule.htm.xml
<id
name="id"
type="long"
column="test_run_schedule_id"
>
<generator class="increment" />
</id>
<property
name="testName"
type="java.lang.String"
column="test_run_name"
not-null="true"
length="45"
/>
<property
name="operation"
type="java.lang.String"
column="operation_included"
not-null="true"
length="500"
/>
<property
name="stTime"
type="java.util.Date"
column="start_time"
not-null="true"
length="19"
/>
<property
name="endTime"
type="java.util.Date"
column="end_time"
not-null="false"
length="19"
/>
当我查看 Mysql 数据库时,它显示了列 start_time [timestamp, NOTNULL]
以及 end_time [timestamp, NOTNULL]
而不是 end_time[timestamp, NULL]
。
因此,当我插入值时,默认情况下end_time
始终被视为CURRENT_TIMESTAMP
。
如何创建 NULLABLE end_time
列?
I am developing a web based application using spring-hibernate combination with Mysql as a database. I have observed 1 problem with hibernate mapping that it doesn't allow me to set null, when type is timestamp. Here is code snippet for better understanding
Here my agenda is - I want to allow user to enter null value for endTime, not for stTime.
schedule.htm.xml
<id
name="id"
type="long"
column="test_run_schedule_id"
>
<generator class="increment" />
</id>
<property
name="testName"
type="java.lang.String"
column="test_run_name"
not-null="true"
length="45"
/>
<property
name="operation"
type="java.lang.String"
column="operation_included"
not-null="true"
length="500"
/>
<property
name="stTime"
type="java.util.Date"
column="start_time"
not-null="true"
length="19"
/>
<property
name="endTime"
type="java.util.Date"
column="end_time"
not-null="false"
length="19"
/>
When I looked into Mysql database, it showing me Columns start_time [timestamp, NOTNULL]
, as well as end_time [timestamp, NOTNULL]
instead of end_time[timestamp, NULL]
.
So when I insert value, end_time
is always taken as CURRENT_TIMESTAMP
by default.
How do I create a NULLABLE end_time
column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论