Java Hibernate:在项目范围内定义类型映射
我正在使用Hibernate和Joda Time,并得到了UserType库的支持 我可以使用以下方法持续约会:Java Hibernate:在项目范围内定义类型映射,java,hibernate,Java,Hibernate,我正在使用Hibernate和Joda Time,并得到了UserType库的支持 我可以使用以下方法持续约会: @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") @Column private DateTime startDate; 然而,我想知道是否有可能在某个地方定义一次映射,而不是在DateTime类型的每个实例上 在从Hibernate 3.4->4.0迁移时,不得不从JodaTime Hibe
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column
private DateTime startDate;
然而,我想知道是否有可能在某个地方定义一次映射,而不是在DateTime
类型的每个实例上
在从Hibernate 3.4->4.0迁移时,不得不从JodaTime Hibernate切换到UserType,我不愿意在整个域模型中乱丢类型声明。您可以实现一个
基本类型
,并在构建会话工厂时注册它。hibernate参考手册在中对此进行了解释 在Usertype的3.0.0.CR1版本中,您可以利用以下类型的自动注册:
PersistentBigMoneyAmount
PersistentMoneyAmount
PersistentCurrency
PersistentCurrencyUnit
PersistentDateTime
PersistentDurationAsString
PersistentInstantAsTimestamp
PersistentLocalDate
PersistentLocalTime
PersistentMonthDayAsString
PersistentPeriodAsString
PersistentTimeOfDay
PersistentYearMonthDay
PersistentYears
要启用此功能,需要将JPA或Hibernate属性“jadira.usertype.autoRegisterUserTypes”设置为“true”
升级usertype.joda Maven工件时,现在称为“usertype.core”
更多信息在这里