A date field in my entity class is defined as below:
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_EXECUTED")
private Date lastExecuted = new Date();
However, when it is persisted to a SQLite3 database through JPA, the database value is always ‘1899-12-30’. Do you have any ideas why?
In the database, the field is defined as DATETIME.
I’ve tried using both SqliteJDBC and Xerial SQLite JDBC.
Update: After turning on SQL debugging in EclipseLink JPA, and turning off parameter binding, it looks like dates are inserted as following:
insert into run (last_executed) values ('{ts ''2012-02-17 10:34:58.013''}');
which, if inserted, manually in SQLite, gives the date ‘1899-12-30’.
Of course, any workarounds would be greatly appreciated.
The date looks correct in the insert, so seems to be some kind of SQLite issue. You should normally use parameter binding, it seems SQLite does allow Timestamp to be bound, or ignores the DATE portion. What if you use TemporalType.DATE?
Perhaps try through raw JDBC to see exactly what your JDBC drivers issue are?
For the printed syntax if not using parameter binding, you can customize this by creating your own DatabasePlatform subclass. The syntax you printed is the standard JDBC timestamp syntax.