joda time 和 hibernate 报错

使用了joda time
import org.joda.time.DateTime;
//...
@Column
private DateTime makeDate;

运行时,提示如下错误
could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize

原因是不能被hibernate序列化。由于类型转换错误引起。
请指定转换类型。
改为如下:
@Column
@DateTimeFormat(iso = ISO.DATE_TIME)
@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
private DateTime makeDate;

或者:
<property type="org.joda.time.contrib.hibernate.PersistentDateTime" name="makeDate"/>


请参见:http://joda-time.sourceforge.net/contrib/hibernate/userguide.html
切记小心谨慎。


猜你喜欢

转载自ichair-126-com.iteye.com/blog/1517417