Introduction

Joda-Time Hibernate support provides classes to persist Joda-Time based date and time objects to a database using Hibernate.

Documentation

It is fairly easy to use this package in your Hibernate environment. There are two main options for the configuration - the hibernate mapping file or annotations.

Hibernate mapping

Add the type attribute to your property configuration. e.g.:

<property type="org.joda.time.contrib.hibernate.PersistentDateTime" name="dateTime"/>
		

Hibernate annotations

Set the type using the @org.hibernate.annotations.Type annotation. e.g.:

@Column
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
private DateTime fromDate;
		

Sometimes there are multiple columns to be specified, as with PersistentDateTimeTZ:

@Columns(columns={@Column(name="startTime"),@Column(name="startTimezone")})
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTimeTZ")
private DateTime startDateTime;
		

Available Types

The main types which can be persisted:

ClassSQL Column Type(s)Description
org.joda.time.contrib.hibernate.PersistentDateTimeTIMESTAMP
org.joda.time.contrib.hibernate.PersistentDateTimeTZTIMESTAMP, VARCHARThis persister uses two columns, to separately store the time value and its timezone
org.joda.time.contrib.hibernate.PersistentInstantBIGINTThis persister uses one column to store the millisconds
org.joda.time.contrib.hibernate.PersistentIntervalTIMESTAMP, TIMESTAMPThis persister uses two columns, to store the start and end of the interval
org.joda.time.contrib.hibernate.PersistentLocalDateTIMESTAMP
org.joda.time.contrib.hibernate.PersistentLocalTimeAsTimeTIMEDepending on your Database you might loose the millisecond part
org.joda.time.contrib.hibernate.PersistentLocalTimeExactINTEGERThe milliseconds are stored as simple integer value, no information loss
org.joda.time.contrib.hibernate.PersistentLocalTimeAsStringVARCHARSame as above, just uses a human readable representation. ISO8601 format - HH:mm:ss.SSSZ
org.joda.time.contrib.hibernate.PersistentLocalDateTimeTIMESTAMP
org.joda.time.contrib.hibernate.PersistentDurationVARCHARThe format is PTnS where n is the value
org.joda.time.contrib.hibernate.PersistentPeriodVARCHARThe format is PnYnMnDTnHnMnS where n is the value

Outdated Types

The following types are now effectively deprecated, however persistence is still available:

ClassSQL Column Type(s)Description
org.joda.time.contrib.hibernate.PersistentTimeOfDayTIMEDepending on your Database you might loose the millisecond part
org.joda.time.contrib.hibernate.PersistentTimeOfDayExactINTEGERThe milliseconds are stored as simple integer value, no information loss
org.joda.time.contrib.hibernate.PersistentYearMonthDayDATE