我正在开发一个基于 web 的应用程序,使用 spring-hibernate 结合 Mysql 作为数据库。我观察到休眠映射的 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 数据库时,它向我显示 Columns start_time [timestamp, NOTNULL]
,end_time [timestamp, NOTNULL]
而不是end_time[timestamp, NULL]
.
因此,当我插入值时,end_time
始终CURRENT_TIMESTAMP
默认为。
如何创建 NULLABLEend_time
列?