I will add this as a separate answer, because in my opinion, this is important information for those who are upgrading to Hibernate 4 and need to switch to the use of constant jadira temporary types. This page is highly rated in google search results for hibernate 4 and jodatime, so I will add it here. (For a separate discussion of this issue, see: Joda DateTime is not stored correctly in the database. )
If you are in a time zone other than UTC, an important configuration is needed to get the same behavior as with the hibernate support type for joda time. The way jadira temporary types work by default is to convert all values โโto UTC before saving the database and converting back to the system time zone when loading values โโfrom the database.
I was burned by this after the update, when I had a lot of timestamps with my exact time zone in the database (UTC + 1 (+2 in summer)). When downloading after switching to Hibernate for 4, 1 or 2 hours (depending on whether there was a timestamp in the summer), a value is added to the database, which means that all existing timestamps were presented incorrectly. In addition, the new timestamp values โโwere stored in the database with the UTC time zone, which led to their correct display in the application, but was incorrect in the database. All in all, a hot mess of timeshares and timestamps.
So, in order to get the same behavior as with hibernate support for joda-time (the datetime is stored in the time zone of the server in question, and the timestamps in the database match what is loaded in the application), the following properties should be added to JPA / Hibernate configuration (in my case hibernate.properties ):
jadira.usertype.autoRegisterUserTypes=true jadira.usertype.databaseZone=jvm jadira.usertype.javaZone=jvm
This ensures that the timestamps in the database will have the same time zone as the application, which in turn will be the jvm time zone (in most cases, the application server clock).
Also, from what I understand, autoRegisterUserTypes -property eliminates the need for @Type -nnotation to select common types, including the Jodatime types DateTime and LocalDate .
Tobb Aug 21 '13 at 12:43 on 2013-08-21 12:43
source share