I am trying to save two objects in a single transaction. On error, I would like my transaction to roll back.
Here is the current attempt:
public Uni<Response> save(...) {
return Uni
.createFrom()
.completionStage(dslContext.transactionResultAsync(configuration -> repo
.insert(... , configuration.dsl())
.flatMap(dataRecord -> Uni
.createFrom()
.publisher(configuration
.dsl()
.insertInto()
.set()
.returning())
.map(ignore -> Response
.builder()
.build()))))
.flatMap(i -> i);
with repo.insert
looking like:
Uni<DataRecord> insert(..., DSLContext dslContext) {
return Uni
.createFrom()
.publisher(dslContext
.insertInto()
.set()
.returning())
.map(dataRecord -> new DataRecord()
.set(...))));
The configuration is based on quarkus-jooq custom context version 2.0, with two additions:
settings.setBindOffsetDateTimeType(true);
settings.setRenderSchema(true);
However. there is no rollback happening in case the second insert fails (I forced it by violating a not null
constraint). I see the exception in my test. I also see the first object. So what would do the trick?