Reputation: 6639
My model has a java.sql.Date
variable and I am able to save just fine.
But whenever I try to retrieve a row it throws this error:
Caused by: java.lang.IllegalArgumentException: field model.date_time_created has type
java.sql.Date, got java.util.Date
at java.lang.reflect.Field.set(Native Method)
at java.lang.reflect.Field.set(Field.java:557)
at com.j256.ormlite.field.FieldType.assignField(FieldType.java:576)
at com.j256.ormlite.stmt.mapped.BaseMappedQuery.mapRow(BaseMappedQuery.java:71)
at com.j256.ormlite.stmt.SelectIterator.getCurrent(SelectIterator.java:270)
at com.j256.ormlite.stmt.SelectIterator.nextThrow(SelectIterator.java:161)
at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:202)
at com.j256.ormlite.stmt.StatementExecutor.queryForAll(StatementExecutor.java:118)
at com.j256.ormlite.dao.BaseDaoImpl.queryForAll(BaseDaoImpl.java:241)
My method to get a list :
public List<Model> getModelList() {
try {
return getHelper().getModelDao().queryForAll();
} catch (SQLException e) {
Timber.e(ErrorUtils.getExceptionString(e));
return null;
}
}
Model is a placeholder
Upvotes: 0
Views: 365
Reputation: 4076
Your import is specifying java.sql.Date
, but your Ormlite field is of type java.util.Date
. The solution is to change the import at the top of your java file so that the correct class is brought in.
Upvotes: 1
Reputation: 116908
IllegalArgumentException: field model.date_time_created has type java.sql.Date, got java.util.Date
The problem turned out to be a bug in ORMLite
. Under Android/SQLite we have to convert all dates to be strings and the conversion from java.sql.Date
was broken. Switching to java.util.Date
will work.
This will be fixed in version 5.0. See: https://github.com/j256/ormlite-android/issues/51
Upvotes: 1