I have table test with JSONB field data.
The following code works perfectly fine. Repository uses JdbcParameterColumnMapper<Test.Data> to map Test.Data to JSON string.
public record Test(Data data) {
public record Data(String foo) {}
}
@Repository
public interface TestRepo extends JdbcRepository {
@Query("""
INSERT INTO test (data)
VALUES (:test.data::jsonb)
""")
void insert(Test data);
}
@Component
public class TestDataJdbcParameterColumnMapper implements
JdbcParameterColumnMapper<Test.Data> {
private final JsonWriter<Test.Data> writer;
public TestDataJdbcParameterColumnMapper(JsonWriter<Test.Data> writer) {
this.writer = writer;
}
@Override
public void set(PreparedStatement stmt, int index, @Nullable Test.Data value)
throws SQLException {
try {
stmt.setString(index, new String(writer.toByteArray(value), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new SQLException(e);
}
}
}
But when I add the following method:
@Query("""
UPDATE test
SET data = :data::jsonb
""")
void replaceData(Test.Data data);
Kora treats Data object as EntityParameter and shows the error:
Parameter usage was not found in query: data
I tried to add @Mapping(TestDataJdbcParameterColumnMapper.class) to the data parameter, but it didn't help.
Seems like there's no way to tell Kora that Data should be processed as SimpleParameter. It would be nice to add such annotation.
I have table
testwithJSONBfielddata.The following code works perfectly fine. Repository uses
JdbcParameterColumnMapper<Test.Data>to mapTest.Datato JSON string.But when I add the following method:
Kora treats
Dataobject asEntityParameterand shows the error:I tried to add
@Mapping(TestDataJdbcParameterColumnMapper.class)to thedataparameter, but it didn't help.Seems like there's no way to tell Kora that
Datashould be processed asSimpleParameter. It would be nice to add such annotation.