Hibernate:定义项目范围内的类型映射
问题描述:
我使用Hibernate & Joda时间,支持UserType库。Hibernate:定义项目范围内的类型映射
我可以使用下面的方法来坚持我的日期:
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column
private DateTime startDate;
不过,我想知道,如果有可能,一旦某处定义这种映射,而不是在DateTime
类型的每个实例。
从Hibernate 3.4 - > 4.0迁移时不得不从JodaTime Hibernate换到UserType,我不愿意在整个域模型中散布类型声明。
答
随着用户类型的3.0.0.CR1版本,则可以利用以下类型的自动注册的:
PersistentBigMoneyAmount
PersistentMoneyAmount
PersistentCurrency
PersistentCurrencyUnit
PersistentDateTime
PersistentDurationAsString
PersistentInstantAsTimestamp
PersistentLocalDate
PersistentLocalTime
PersistentMonthDayAsString
PersistentPeriodAsString
PersistentTimeOfDay
PersistentYearMonthDay
PersistentYears
要启用此功能,您需要设置JPA或休眠财产“jadira.usertype .autoRegisterUserTypes'为'true'。
升级usertype.joda时Maven工件现在称为'usertype.core'。