由hibernate 的逆向工具从数据库表生成的*.hbm.xml ,对于数据库的date类型生成以下:
<
property
name
=
"crttime"
type= "date">
<
column
name
=
"CRTTIME"
length
=
"7"
/>
</
property
>
程序中的类型:
但经过程序
setCrttime(new Date()) 的时候,插入到数据库的日期只到天,没有小时之后的数据。
网上查了一下,有的说能够修改type类型为 java.util.Date, 但实验发现hibernate不能识别此类型,修改成
timestamp则能够。
以下是最终修改:
<
property
name
=
"crttime"
type
=
"timestamp"
>
<
column
name
=
"CRTTIME"
/>
</
property
>
我把
length
=
"7" 也去掉了