Replies: 2 comments 9 replies
|
Use import io.quarkus.test.TestTransaction;
import org.junit.jupiter.api.Test;
@QuarkusTest
public class UserServiceTest {
@Inject
EntityManager em;
@Inject
DSLContext dsl; // jOOQ
@Test
@TestTransaction // wraps test in transaction, rolls back at end
void testJooqAndEntityManager() {
// EntityManager operations
User user = new User("test@example.com");
em.persist(user);
em.flush(); // sync before jOOQ queries
// jOOQ queries — they run in the same transaction
Record record = dsl.select()
.from(USER)
.where(USER.EMAIL.eq("test@example.com"))
.fetchOne();
// Both participate in the same @TestTransaction
// Everything rolls back after test
}
}Important notes:
quarkus.datasource.db-kind=postgresql
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/testdb
quarkus.datasource.jdbc.transactions=normal # jTA coordination
For jOOQ + EntityManager in production (not test): @Transactional
public void businessLogic() {
// EM + jOOQ in same transaction via CDI + DataSource
em.persist(entity);
dsl.update(TABLE).set(...).execute(); // same transaction
} |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Jooq is used mainly in our application. Additionally we use the oubox package which uses
eintityManager.An interesting thing happens when we want to test our solution for the oubox-pattern.
The test cases are annotated with
@TestTransactionand of course somewhere in the application, there is an@Transactionalannotation to ensure the single transaction is done because of the outbox-pattern. If the oubox table is queried with native query the tests give the expected result.
If the oubox table is queried with jooq the test give not the expected result. Quite precisely, it looks like the outbox table is empty. The result of the query does not return any records.
Why is there a difference between native query and jooq?
Of course, remove is turned off during testing.
%test.quarkus.debezium-outbox.remove-after-insert = falseAll reactions