1 / 14

Jadira Usertype

Jadira Usertype. Integrating Hibernate with Joda Time and JSR 310 http://usertype.sourceforge.net/. 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)

jacie
Download Presentation

Jadira Usertype

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  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) • 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 JodaLocalTime to the database is even more lightweight. Uses Super Type Tokens (http://www.artima.com/weblogs/viewpost.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. • JodaTimeContrib 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’sJodaTime and JSR 310 modules provide equivalent user types

  14. Questions?

More Related