Skip to content

Instantly share code, notes, and snippets.

@fabriciofx
Created April 27, 2014 01:07
Show Gist options
  • Select an option

  • Save fabriciofx/11335227 to your computer and use it in GitHub Desktop.

Select an option

Save fabriciofx/11335227 to your computer and use it in GitHub Desktop.
package icob.model.entity.converter;
import java.sql.Timestamp;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.joda.time.LocalDateTime;
@Converter(autoApply = true)
public class LocalDateTimeConverter
implements AttributeConverter<LocalDateTime, Timestamp> {
public Timestamp convertToDatabaseColumn(LocalDateTime dateTime) {
return new Timestamp(dateTime.toDateTime().getMillis());
}
public LocalDateTime convertToEntityAttribute(Timestamp date) {
return LocalDateTime.fromDateFields(date);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment