I have the following model:
@Table("organisation")
public class OrganisationModel {
@Id
@Column("id_organisation")
private OrganisationId id;
@Column("id_parent")
private OrganisationId parentId;
}
The IDs in the database are Integers. The class OrganisationId
simply wraps the Integers. To map the IDs I define the following Converters:
public class OrganisationModelReadingConverter implements Converter<Row, OrganisationModel> {
@Override
public OrganisationModel convert(Row source) {
OrganisationModel model = new OrganisationModel();
model.setId(new OrganisaitonId(source.get("id_organisation", Integer.class)));
model.setParentId(new OrganisationId(source.get("id_parent", Integer.class)));
return model;
}
}
public class OrganisationModelWritingConverter implements Converter<OrganisationModel, OutboundRow> {
@Override
public OutboundRow convert(OrganisationModel source) {
OutboundRow outboundRow = new OutboundRow();
outboundRow.put("id_organisation", source.getId().getValue());
outboundRow.put("id_parent", source.getParentId().getValue());
return outboundRow;
}
}
and register the Converters with:
@Configuration
public class R2dbcConfiguration {
@Bean
R2dbcCustomConversions customConversions(ConnectionFactory connectionFactory) {
R2dbcDialect dialect = DialectResolver.getDialect(connectionFactory);
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(new OrganisationModelReadingConverter());
converters.add(new OrganisationModelWritingConverter());
return R2dbcCustomConversions.of(dialect, converters);
}
}
I expect that the convert() methods of the registered Converters are called but they never are. The Bean for the R2dbcCustomConversions is initialised at start up.
What am I doing wrong here?