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:

Class SQL Column Type(s) Description
org.joda.time.contrib.hibernate.PersistentDateTime TIMESTAMP
org.joda.time.contrib.hibernate.PersistentDateTimeTZ TIMESTAMP, VARCHAR This persister uses two columns, to separately store the time value and its timezone
org.joda.time.contrib.hibernate.PersistentInstant TIMESTAMP This persister uses one column to store the timestamp
org.joda.time.contrib.hibernate.PersistentInstantAsBigInt BIGINT This persister uses one column to store the millisconds
org.joda.time.contrib.hibernate.PersistentInterval TIMESTAMP, TIMESTAMP This persister uses two columns, to store the start and end of the interval
org.joda.time.contrib.hibernate.PersistentLocalDate TIMESTAMP
org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime TIME Depending on your Database you might loose the millisecond part
org.joda.time.contrib.hibernate.PersistentLocalTimeAsTimestamp TIMESTAMP
org.joda.time.contrib.hibernate.PersistentLocalTimeExact INTEGER The milliseconds are stored as simple integer value, no information loss
org.joda.time.contrib.hibernate.PersistentLocalTimeAsString VARCHAR Same as above, just uses a human readable representation. ISO8601 format - HH:mm:ss.SSSZ
org.joda.time.contrib.hibernate.PersistentLocalDateTime TIMESTAMP
org.joda.time.contrib.hibernate.PersistentDuration VARCHAR The format is PTnS where n is the value
org.joda.time.contrib.hibernate.PersistentDurationAsMilliseconds BIGINT Integer milliseconds
org.joda.time.contrib.hibernate.PersistentPeriod VARCHAR The format is PnYnMnDTnHnMnS where n is the value

Outdated Types

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

Class SQL Column Type(s) Description
org.joda.time.contrib.hibernate.PersistentTimeOfDay TIME Depending on your Database you might loose the millisecond part
org.joda.time.contrib.hibernate.PersistentTimeOfDayExact INTEGER The milliseconds are stored as simple integer value, no information loss
org.joda.time.contrib.hibernate.PersistentYearMonthDay DATE