-
Notifications
You must be signed in to change notification settings - Fork 18
Add possibility to mark @Repository param as simple #155
Copy link
Copy link
Open
Labels
module: databaseRelated to module - databaseRelated to module - database
Description
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.
Metadata
Metadata
Assignees
Labels
module: databaseRelated to module - databaseRelated to module - database