quarkus: @QuarkusTest does not handle entity updates
Describe the bug A test creates, updates and reads the entity in separate transactions. The last transaction, which reads the entity, can find it, but the entity still has the same value as when it was created.
Expected behavior After an entity is updated in one transaction, the change should be visible in the next transaction.
Actual behavior After an entity is updated in one transaction, it has the same value as when it was created.
To Reproduce Steps to reproduce the behavior:
- Make a test that calls three methods: persist, update, and read. Test method is not
@Transactional
, while called methods are. - Run the test.
Configuration
quarkus.datasource.driver=org.h2.Driver
quarkus.datasource.url=jdbc:h2:file:./persons
quarkus.datasource.username=sa
quarkus.datasource.password=sa
quarkus.hibernate-orm.database.generation=drop-and-create
Screenshots (If applicable, add screenshots to help explain your problem.)
Environment (please complete the following information):
- Output of
uname -a
orver
: Microsoft Windows [Version 10.0.19041.21] - Output of
java -version
: 1.8 - GraalVM version (if different from Java):
- Quarkus version or git rev: 1.3.0.Alpha1
Additional context The reproducer is attached: test-update2.zip
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 21 (13 by maintainers)
Commits related to this issue
- Test for #7102 — committed to FroMage/quarkus by FroMage 4 years ago
- Test for #7102 — committed to FroMage/quarkus by FroMage 4 years ago
- Merge pull request #9577 from FroMage/7102 Test for #7102 — committed to quarkusio/quarkus by FroMage 4 years ago
- [UnitTest] Minimal UnitTest for quarkusio/quarkus#7102. Signed-off-by: Juri Berlanda <juri.berlanda@tuwien.ac.at> — committed to j-be/quarkus-7102 by deleted user 4 years ago
Added your test at https://github.com/quarkusio/quarkus/pull/9577 and it passes. We must have fixed this already in
master
.Narayana is dependency of Hibernate, there is no need to include it per se.
Well we really need to make sure all the classes that use the entity are transformed as well, otherwise even user-defined accessors won’t get called and it will be all confusing.
In your test you have @Transactional on a method that is called by other methods on the same class. CDI interceptors are not applied for self invocation, only for external invocation (e.g. when you inject the bean and invoke on it). As no transaction is active this is why the change is not persisted.