Skip to content

Add possibility to mark @Repository param as simple #155

@mitasov-ra

Description

@mitasov-ra

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions