Persisting Joda-Time Fields with openjpa

Lately i became curious about how to store joda-time objects into a database with openjpa. Well, its supprisingly easy if you only want to store/retrieve the objects:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import org.apache.openjpa.persistence.Persistent;
import org.joda.time.DateTime;

public class EntityA {
private Integer id;

private DateTime startDate;

Thats it .. of course what happens is, that openjpa does serialize the DateTime object and stores them as a BLOB field in the database, which might not be always the preferred solution.

Another way would be to add @Externalizer and @Factory annotations to the DateTime object, and write a custom convertor that would convert DateTime to SQL Timestamp or similar.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply