hibernate 中配置MYSQL日期类型自动赋值问题
报错:ERROR JDBCExceptionReporter:101 - Field 'addDate' doesn't have a default value
当在hibernate 中配置需要自动设置值的日期类型时候,只能使用timestamp时间戳类型,并且在<property>标签中配置时候不可以直接配置属性TYPE=“timestamp”这样情况下,当使用hibernate的hbm2ddl工具时候创建的表字段为datetime类型,而非我们所想要的时间戳timestamp类型。我们应该在<column>标签中配置sql-type="timestamp"
如下:
正确配置:
(需要自动设置值,即数据库自动设置系统时间)日期配置
<property name="addDate" generated="insert" not-null="true">
<column name="addDate" sql-type="timestamp" default="CURRENT_TIMESTAMP"/>
</property>
或:
<property name="addDate" generated="insert" not-null="true"> <column name="addDate" sql-type="timestamp"></column> </property>