-
Notifications
You must be signed in to change notification settings - Fork 20
Add possibility to mark @Repository param as simple #155
Labels
module: database
Related to module - database
Comments
The working workaround for me: public interface TestRepo extends JdbcRepository {
@Query("""
INSERT INTO test (data)
VALUES (:test.data::jsonb)
""")
void insert(Test data);
void replaceData(Test.Data data);
}
@Repository
public abstract class ATestRepo implements TestRepo {
private final JsonWriter<Test.Data> writer;
public TestRepo(JsonWriter<Test.Data> writer) {
this.writer = writer;
}
@Query("""
UPDATE test
SET data = :data::jsonb
""")
public abstract void replaceDataInternal(String data);
@Override
public void replaceData(Test.Data data) {
replaceDataInternal(new String(writer.toByteArray(data), StandardCharsets.UTF_8))
}
} |
Given such classes: @KoraApp
interface MyApp : JdbcDatabaseModule, ConfigModule, JsonCommonModule {
class MyRoot(val myRepo: MyRepo) : Lifecycle {
override fun init(): Mono<Void> {
return Mono.empty()
}
override fun release(): Mono<Void> {
return Mono.empty()
}
}
@Root
fun myRoot(myRepo: MyRepo): MyRoot {
return MyRoot(myRepo)
}
@Tag(Json::class)
fun <T> myMapper(writer: JsonWriter<T>) : JdbcParameterColumnMapper<T> {
return JdbcParameterColumnMapper { stmt, index, value ->
try {
stmt.setString(index, String(writer.toByteArray(value), StandardCharsets.UTF_8))
} catch (e: IOException) {
throw RuntimeException(e)
}
}
}
}
@Repository
interface MyRepo : JdbcRepository {
@Json
data class Foo(@Tag(Json::class) val bar: Bar) {
@Json
data class Bar(val s: String)
}
@Query(
"""
INSERT INTO foo (bar)
VALUES
(:foo.bar::jsonb)
"""
)
fun insert(foo: Foo)
@Query(
"""
UPDATE foo
SET bar = :bar::jsonb
"""
)
fun updateBar(@Tag(Json::class) bar: Foo.Bar)
} Everything works as expected, can you confirm @mitasov-ra this on your side and I will close issue as resolved? |
Issue with NPE is not reproducible in |
@mitasov-ra any progress on testing this out? |
Atm I'm waiting for new release with fix for #187 |
Just've checked, NPE from #166 still reproduces if I add
VersionsJVM: corretto-17.0.6 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have table
test
withJSONB
fielddata
.The following code works perfectly fine. Repository uses
JdbcParameterColumnMapper<Test.Data>
to mapTest.Data
to JSON string.But when I add the following method:
Kora treats
Data
object asEntityParameter
and shows the error:I tried to add
@Mapping(TestDataJdbcParameterColumnMapper.class)
to thedata
parameter, but it didn't help.Seems like there's no way to tell Kora that
Data
should be processed asSimpleParameter
. It would be nice to add such annotation.The text was updated successfully, but these errors were encountered: