Created
December 28, 2009 01:11
-
-
Save Villane/264474 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.persistence._ | |
import org.eclipse.persistence.annotations.Converter | |
import org.eclipse.persistence.annotations.Convert | |
class Entity { | |
@Column(nullable=false, updatable=false) | |
@Converter(name="jodadatetime", converterClass=classOf[JodaTimeConverter]) | |
@Convert("jodadatetime") | |
var created: org.joda.time.DateTime = _ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.persistence.mappings.DatabaseMapping; | |
import org.eclipse.persistence.mappings.converters.Converter; | |
import org.eclipse.persistence.sessions.Session; | |
import org.joda.time.DateTime; | |
import java.sql.Timestamp; | |
public class JodaTimeConverter implements Converter { | |
private static final long serialVersionUID = 1L; | |
public Object convertDataValueToObjectValue(Object dataValue, | |
Session session) { | |
Timestamp value = (Timestamp) dataValue; | |
return new DateTime(value); | |
} | |
public Object convertObjectValueToDataValue(Object objectValue, | |
Session session) { | |
DateTime value = (DateTime) objectValue; | |
return new Timestamp(value.getMillis()); | |
} | |
public void initialize(DatabaseMapping mapping, Session session) { | |
} | |
public boolean isMutable() { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment