Download presentation
Presentation is loading. Please wait.
Published byBerniece Lawrence Modified over 9 years ago
1
Jadira Usertype Integrating Hibernate with Joda Time and JSR 310 http://usertype.sourceforge.net/
2
Background Hibernate: Object Relational Mapping Framework for Java. At one time a defacto standard, Hibernate is now also the leading implementation of JPA (Java Persistence API) Joda Time: Widely used API for Date and Time. Superior to java.util.Date and Calendar for many reasons… thread safety, immutable, distinguishes Date, Time, DateTime and Time Zones effectively JSR310: Overhaul of core Java’s date and time APIs based on Joda Time. Scheduled for Java 7
3
Why Jadira Usertype JSR310 does not (yet) integrate with JPA so alternative mechanism is required. Hibernate provides APIs for implementing Usertypes or User-Defined Types Existing contributed user type support for Joda Time has not been updated for some time JDBC, Hibernate and Joda Time Contrib all (somewhat unexpectedly) modify dates and times when JVM and Database have different timezones – no good at all for correctly storing a Local Date or DateTime with specific zone.
4
Project Structure JSR 310 support’s module structure is similar but tests utilise Hibernate 3.6 and JPA2
5
Timeline VersionDateDescription 1.507-10-2010 Bugfix (NullPointerException when using Hibernate 3.5) 1.404-10-2010Hibernate 3.6 compatibility 1.3.113-09-2010 UTC DateTime Behaviour Tweak 1.306-09-2010Fix Java 5 Support 1.201-06-2010 Published to Maven Central 1.130-04-2010 New Types (including Joda Time) 1.022-04-2010 Initial Release (supports JSR 310)
6
Design Problems Various representations of types available (String, milliseconds since 1970, SQL Date, Timestamp etc) Representations can be qualified with and without zones and mapped to single or multiple columns Addressing the JDBC offsetting problem (http://blog.jadira.co.uk/blog/2010/5/1/javasqldate-types-and-the-offsetting-problem.html)http://blog.jadira.co.uk/blog/2010/5/1/javasqldate-types-and-the-offsetting-problem.html Maintenance and testing New challenges – supporting Hibernate 3.6
7
Mapping Columns: Column Mapper Most behaviour is consolidated into abstract classes that are parameterized by the type they map to…
8
Mapping Columns: Column Mapper (2) … yielding lightweight column mapping implementations
9
Bringing it all together The type that uses this column-mapper to persist a Joda LocalTime to the database is even more lightweight. Uses Super Type Tokens (http://www.artima.com/weblogs/viewp ost.jsp?thread=206350)http://www.artima.com/weblogs/viewp ost.jsp?thread=206350
10
Bringing it all together (2) Multi-column types use n column mappers Can reuse mappers written for single column mappings For example: OffsetDateTime is stored as an offset and a LocalDateTime to two columns
11
Quality PMD, Findbugs, JDepend used for automated metrics capture Cobertura provides code coverage information… Unit Tests use DBUnit, embedded H2Database and JPA: Tests verify that the types actually stored in the database are written, stored and read correctly. JodaTime Contrib unit tests never verified what was stored… the value was offset incorrectly when written and again when read During testing uncovered and reported some issues in other open source projects: JSR 310 Public Draft (relating to formatting of sub-seconds in the Period type) DBUnit (formatting of milliseconds and nanoseconds in Timestamp types)
12
Hibernate 3.6 Support Problem: Hibernate 3.6 changed its Type API, but its not synced to Maven central Solution: Check for presence of Hibernate 3.6 API and use reflection if available; plan to revisit when JBoss start synchronising their releases to Maven Central
13
Who Uses Jadira Usertype? Releases 1.0 and 1.1 totalled 100s of downloads; Since 1.2 distribution is via Maven Central, statistics are not available; Since April, Joda Time project has recommended Usertype; Two community reported bugs and fixes received; Project used by my employer to support business domains in global sales, operations, financing, integration and web channels; Project supports equivalents to all Joda Time Contrib types providing ease of migration; Wherever possible Usertype’s JodaTime and JSR 310 modules provide equivalent user types
14
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.