Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate 4 and joda-time

are they happily married ?

I am using the latest version of hibernate (4) and version 1.3 of joda-time hibernate support, which I also believe to be the current latest release.

Everything seems to be working OK (date columns created as expected) when using annotations :

@Column @Type(type="org.joda.time.contrib.hibernate.PersistentLocalDate") private LocalDate myDate;  

Are their any known problems with using these versions together ?

Update Well turns out the columns get created but unable to populate with any data :

Handler processing failed; nested exception is java.lang.AbstractMethodError: org.joda.time.contrib.hibernate.PersistentLocalDateTime.nullSafeSet

They are incompatible, and I should be using usertype. See answer below.

like image 899
NimChimpsky Avatar asked Jan 23 '12 16:01

NimChimpsky


People also ask

What is the replacement of Joda-time?

time (JSR-310) which is a core part of the JDK which replaces joda library project.

Is Joda-time deprecated?

So the short answer to your question is: YES (deprecated).

Is Joda-time followed in Java 8?

Joda-Time is an API created by joda.org which offers better classes and having efficient methods to handle date and time than classes from java. util package like Calendar, Gregorian Calendar, Date, etc. This API is included in Java 8.0 with the java.

What is Joda-time in Java?

Joda-Time is the most widely used date and time processing library, before the release of Java 8. Its purpose was to offer an intuitive API for processing date and time and also address the design issues that existed in the Java Date/Time API.


1 Answers

A distinct paucity of documentation, means it might be helpful for me to write down the steps required for integration. Make sure your libraries are up to date.

You'll need : [assuming you already have hibernate4]

Latest version of joda-time

<dependency>     <groupId>joda-time</groupId>     <artifactId>joda-time</artifactId>     <version>2.0</version> </dependency> 

and usertype lib

<dependency>     <groupId>org.jadira.usertype</groupId>     <artifactId>usertype.core</artifactId>     <version>3.0.0.CR1</version> </dependency> 

Then use the following in entity classes (doesn't have to be LocalDateTime, could be any of the persisted classes available) :

import org.joda.time.LocalDateTime; 

and for column definition:

@Column(name="updated", nullable = false) @Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime") private LocalDateTime updated; 
like image 178
NimChimpsky Avatar answered Sep 20 '22 09:09

NimChimpsky