CURRENT_TIMESTAMP sqlite issue

151 views
Skip to first unread message

Joe Falconer

unread,
Apr 25, 2017, 10:46:34 PM4/25/17
to ORMLite Developers

Having trouble using the CURRENT_TIMESTAMP keyword in Sqlite with Ormlite 5.0.


There appears to be a couple of ways to approach:

  1. Use a custom persister as here.

  2. Modify the table schema to include the CURRENT_TIMESTAMP as here.

I can get both to work for record creation. However, retrieval throws a ParseException (see below).


Tried various combinations of annotations on the field itself but can't seem to resolve.

@DatabaseField(columnName = TIMESTAMP, readOnly = true) private Timestamp timestamp = null;


The date string seems to be saved in a valid form that should be recognised (Unparseable date: "2017-04-10 20:26:52"). Using matching format designator in annotation makes no difference.



Any ideas?



java.sql.SQLException: Error parsing time stamp
at org.sqlite.jdbc3.JDBC3ResultSet.getTimestamp(JDBC3ResultSet.java:538)
at com.j256.ormlite.jdbc.JdbcDatabaseResults.getTimestamp(JdbcDatabaseResults.java:175)
at com.j256.ormlite.field.types.DateType.resultToSqlArg(DateType.java:50)
at com.j256.ormlite.field.BaseFieldConverter.resultToJava(BaseFieldConverter.java:26)
at com.j256.ormlite.field.FieldType.resultToJava(FieldType.java:841)
at com.j256.ormlite.stmt.mapped.BaseMappedQuery.mapRow(BaseMappedQuery.java:61)
at com.j256.ormlite.stmt.SelectIterator.getCurrent(SelectIterator.java:284)
at com.j256.ormlite.stmt.SelectIterator.nextThrow(SelectIterator.java:168)
at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:202)
at com.j256.ormlite.stmt.StatementExecutor.queryForAll(StatementExecutor.java:126)
at com.j256.ormlite.dao.BaseDaoImpl.queryForAll(BaseDaoImpl.java:248)
at nz.co.discoveryservices.etsyV2.integrationtests.TestShopSearchExtractorExceptions.invalidJsonShouldGenerateShopSearchResultsExceptionRecordsInDatabase_NoRetries(TestShopSearchExtractorExceptions.java:1294)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.text.ParseException: Unparseable date: "2017-04-10 20:26:52"
    at java.text.DateFormat.parse(Unknown Source)
    at org.sqlite.jdbc3.JDBC3ResultSet.getTimestamp(JDBC3ResultSet.java:535)
    ... 40 more


Reply all
Reply to author
Forward
0 new messages