Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.j256.ormlite.examples.datapersister;
A custom persister that is able to store the Joda org.joda.time.DateTime class in the database as epoch-millis long integer. This overrides the com.j256.ormlite.field.types.DateTimeType which uses reflection instead. This should run faster. This can be specified using com.j256.ormlite.field.DatabaseField.persisterClass() or registered with com.j256.ormlite.field.DataPersisterManager.registerDataPersisters(com.j256.ormlite.field.DataPersister[]).

public class DateTimePersister extends DateTimeType {
	private static final DateTimePersister singleTon = new DateTimePersister();
	private DateTimePersister() {
		super(.new Class<?>[] { DateTime.class });
	public static DateTimePersister getSingleton() {
		return ;
	public Object javaToSqlArg(FieldType fieldTypeObject javaObject) {
		DateTime dateTime = (DateTimejavaObject;
		if (dateTime == null) {
			return null;
else {
			return dateTime.getMillis();
	public Object sqlArgToJava(FieldType fieldTypeObject sqlArgint columnPos) {
		return new DateTime((LongsqlArg);
New to GrepCode? Check out our FAQ X