Question:
When I use IgniteCache.get(key) to get the corresponding entity, ignite throws the following error "Can not set java.time.LocalDateTime field org.apache.ignite.examples.model.Person.createdTime to java.sql .Timestamp"
Conditions and usage:
- In ignite 2.14.0, I use H2 as the underlying storage;
- In
CacheJdbcPojoStoreFactory, I configured the mapping between the datetime type of the database and JDK8's LocalDateTime:
new JdbcTypeField(Types.TIMESTAMP, "created_time", LocalDateTime.class, "createdTime")
Problem analysis:
By default, CacheJdbcPojoStore uses org.apache.ignite.cache.store.jdbc.JdbcTypesTransformer#getColumnValue to parse jdbc's ResultSet.
For the LocalDateTime type of JDK8, java.sql.ResultSet#getObject(int) is used to obtain the value of the specified column (here it is read as java.sql.Timestamp). When the object is finally constructed, the type is inconsistent Causes sun.reflect.FieldAccessor#set assignment to fail.
Repair suggestion:
I want to parse the value of the specified column using java.sql.ResultSet#getObject(int, java.lang.Class<T>), what do you think?