Given MySQL table schema, entity class and custom converter...
Table schema
CREATE TABLE task
(
id int NOT NULL AUTO_INCREMENT,
owner binary(16) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (owner) REFERENCES user (id)
);
Entity class
@Data
@Table("task")
public class TaskEntity {
@Id
private Integer id;
private AggregateReference<UserEntity, UUID> owner;
}
Custom converter
@Component
public class UuidFromBin implements Converter<byte[], UUID> {
@Override
public UUID convert(byte[] source) {
ByteBuffer byteBuffer = ByteBuffer.wrap(source);
long high = byteBuffer.getLong();
long low = byteBuffer.getLong();
return new UUID(high, low);
}
}
This should convert value of the binary id column into UUID id field of TaskEntity when the table is read, but the following exception is thrown.
org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Byte] to type [org.springframework.data.jdbc.core.mapping.AggregateReference<jp.co.sre.aip.samplebasic.core.app.repository.UserEntity, java.util.UUID>] for value [-121]
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:47)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:182)
at org.springframework.core.convert.support.ArrayToObjectConverter.convert(ArrayToObjectConverter.java:68)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:182)
...
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Byte] to type [java.util.UUID]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:294)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:185)
at org.springframework.data.jdbc.core.convert.AggregateReferenceConverters$SimpleTypeToAggregateReferenceConverter.convert(AggregateReferenceConverters.java:131)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
Can you provide a minimal yet complete sample that reproduces the problem?
You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Given MySQL table schema, entity class and custom converter...
Table schema
Entity class
Custom converter
This should convert value of the binary
id
column into UUIDid
field ofTaskEntity
when the table is read, but the following exception is thrown.