Reputation: 73
Insertion part is working properly but when I update custom enum set column, this exception is thrown
java.lang.AssertionError: expectation "expectNext(1)" failed (expected: onNext(1); actual: onError(java.lang.IllegalArgumentException: Cannot encode parameter of type java.util.ArrayList ([TYPE1])))
DB Config
@Configuration
@RequiredArgsConstructor
public class DatabaseConfig extends AbstractR2dbcConfiguration {
... missing code
@Bean
public ConnectionFactory connectionFactory() {
PostgresqlConnectionFactory postgresqlConnectionFactory = new PostgresqlConnectionFactory(
PostgresqlConnectionConfiguration
.builder()
... missing code
.codecRegistrar(
EnumCodec
.builder()
.withEnum("interface_type", InterfaceType.class)
.build()
)
.build()
);
... missing code
}
@Override
protected List<Object> getCustomConverters() {
return List.of(
new InterfaceTypeWriter()
);
}
}
Converter
@WritingConverter
public class InterfaceTypeWriter extends EnumWriteSupport<InterfaceType> {}
Domain object
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
@Table
public class DomainObject {
@Id
private Long id;
@Column("interface_types")
private Set<InterfaceType> interfaceTypes; //InterfaceType is a custom enum
}
Dao service
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
@Service
public class Dao {
private final R2dbcEntityTemplate template;
public Mono<Long> update(Long id, DomainObject object) {
Update update = Update
.update("interface_types", object.getInterfaceTypes());
Query query = Query.query(Criteria.where("id").is(id));
return template.update(query, update, DomainObject.class);
}
Table
CREATE TABLE my_table (
id BIGINT PRIMARY KEY,
interface_types interface_type[]
);
Upvotes: 0
Views: 43