Hibernation: Determine the type of display for the entire project.

I use Hibernate and Joda Time with support for the UserType library.

I can save my dates using the following approach:

@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") @Column private DateTime startDate; 

However, I am wondering if this mapping can be defined somewhere somewhere, and not on every instance of the DateTime type.

When switching from Hibernate 3.4 β†’ 4.0, I had to switch from JodaTime Hibernate to UserType, I do not want type declarations to be littered in the entire domain model.

+4
source share
2 answers

With the release of 3.0.0.CR1 Usertype, you can use the following types of auto-registration:

 PersistentBigMoneyAmount PersistentMoneyAmount PersistentCurrency PersistentCurrencyUnit PersistentDateTime PersistentDurationAsString PersistentInstantAsTimestamp PersistentLocalDate PersistentLocalTime PersistentMonthDayAsString PersistentPeriodAsString PersistentTimeOfDay PersistentYearMonthDay PersistentYears 

To enable this feature, you need to set the JPA or Hibernate property 'jadira.usertype.autoRegisterUserTypes' to true.

When updating the artifact artifact, usernamepe.joda is now called "usertype.core".

Further information here http://blog.jadira.co.uk/blog/2012/1/19/release-jadira-usertype-300cr1-with-support-for-joda-money-0.html

+3
source

You can implement BasicType and register it when creating a SessionFactory . The hibernation reference guide explains this in section 6.4.1 .

0
source

Source: https://habr.com/ru/post/1391543/


All Articles