In my project I have the following entity which can be successfully saved in Postgres:
public class Aggregate {
@Id
private UUID id;
private JsonNode data;
// getters and setters omitted
}
When I try to save the same entity in SQLite I get the following exception:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Integer] to type [java.util.UUID]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:322) ~[spring-core-5.3.5.jar:5.3.5]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195) ~[spring-core-5.3.5.jar:5.3.5]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175) ~[spring-core-5.3.5.jar:5.3.5]
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.convertIfNecessary(ConvertingPropertyAccessor.java:120) ~[spring-data-commons-2.4.6.jar:2.4.6]
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:63) ~[spring-data-commons-2.4.6.jar:2.4.6]
at org.springframework.data.jdbc.core.JdbcAggregateChangeExecutionContext.setIdAndCascadingProperties(JdbcAggregateChangeExecutionContext.java:337) ~[spring-data-jdbc-2.1.6.jar:2.1.6]
at org.springframework.data.jdbc.core.JdbcAggregateChangeExecutionContext.populateIdsIfNecessary(JdbcAggregateChangeExecutionContext.java:305) ~[spring-data-jdbc-2.1.6.jar:2.1.6]
at org.springframework.data.jdbc.core.AggregateChangeExecutor.execute(AggregateChangeExecutor.java:52) ~[spring-data-jdbc-2.1.6.jar:2.1.6]
at org.springframework.data.jdbc.core.JdbcAggregateTemplate.store(JdbcAggregateTemplate.java:339) ~[spring-data-jdbc-2.1.6.jar:2.1.6]
at org.springframework.data.jdbc.core.JdbcAggregateTemplate.save(JdbcAggregateTemplate.java:149) ~[spring-data-jdbc-2.1.6.jar:2.1.6]
at org.springframework.data.jdbc.repository.support.SimpleJdbcRepository.save(SimpleJdbcRepository.java:60) ~[spring-data-jdbc-2.1.6.jar:2.1.6]
Table definition for SQLite:
create table aggregate
(
id text primary key,
data text not null
);
For some reason Spring Data JDBC tries to set an id of type integer in the aggregate although it's a) of another type and b) already there. I experimented with a different IdGenerator
, using without rowid
in the table definiton but nothing changed.
I'm using Spring Data JDBC 2.1.6 and xerial/sqlite-jdbc 3.34.0.
How can I fix this?
Update to answer Jens Schauder's question: I forgot to mention the callback that sets the UUID appropriately. I also have two converters to translate between JsonNode
and PGobject
(not shown here).
@Component
public class AggregateCallback implements BeforeConvertCallback<Aggregate> {
@Override
public Aggregate onBeforeConvert(final Aggregate aggregate) {
if (aggregate.getId() == null) {
aggregate.setId(UUID.randomUUID());
}
return aggregate;
}
}
Regardless of the database the AggregateCallback
is called, but with SQLite the exception is thrown after the execution of the callback.