Skip to content

AggregateReference conversion does not honor custom converters #1750

Closed
@kota65535

Description

@kota65535

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)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions