-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@QuarkusTest does not handle entity updates #7102
Comments
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. |
@mkouba can you confirm that there are no plans to add support for self-interception? I know this is a topic that comes up every now and then but I can't remember what the spec has to say about it. |
Things get a little weird here. If I remove @transactional and put
|
ok, this is weird, I will investigate |
Turns out I was wrong, we do support self invocation for interceptors, so now I have no idea what is going on here, I will investigate further. |
@FroMage the test does not seem to be transformed to use the getters/setters, so the dirty checker is not picking up that the entity is dirty. |
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. |
Today I tried to run my regular tests, which run perfectly under Java 8, under Java 11. The result was a hot mess: half of the tests failed, probably due to some transaction issues. It only happens on Windows, even in WSL2 tests run fine. Should I open a new issue for that or you think that may be related to this issue? To be honest, I do not have a clue about what is going on. Do you test on Windows Java 11? |
Here is more: if a class implementing the PanacheRepository is marked as |
This looks like a different issue. |
I believe I am in the same situation, but there is something strange when it is not in test mode too. I did a test via POSTMAN and with MSSQL database. I followed the request in the database, the entity is updated as expected, but in the application I use the command More informations: #7163 |
@zeljkot The I don't know why the lack of dependency does not generate an error. In the tests with TransactionManager and UserTransaction the following message started to be displayed when the commit line is executed: Project with my changes: |
Narayana is dependency of Hibernate, there is no need to include it per se. |
My quarkus logs with log trace enabled: https://send.firefox.com/download/1017dc8221806b4b/#HN3XWg9TzL4hc_db5reZ3Q |
@stuartwdouglas Yes, we do. The behavior is undefined from the spec POV.
@zeljkot Yes, this is a known issue - repository class is transformed/methods are generated and so the CDI container does not see the methods at all. And for entities there is a problem with static methods - these are not intercepted by design (as defined by the spec). |
I find a way around this problem, in the test files I did not do operations with the database directly, I did all through API. It worked for me. |
Added your test at #9577 and it passes. We must have fixed this already in |
Please reopen if you experience this again with |
I think this was fixed by #7188 |
Signed-off-by: Juri Berlanda <[email protected]>
I am still able to reproduce the issue (or at least a very similar one) with Quarkus 1.5.1.Final. The issue on my side seems to hinge on See https://github.com/j-be/quarkus-7102 for a minimal project reproducing the issue. EDIT: I extended the TestProject to better show what I mean with |
This is a different issue, and the behaviour you are seeing is expected. The EntityManager will always use the same object for a given ID. When you call findAll that object is loaded from the database. When you edit it in a new transaction the new transaction creates a new EntityManager, however the original EM still has the old entity loaded. When you then call findById the EM just returns the original object loaded by listAll(), which has not been modified yet. If you want to see the updated object you need to call EntityManager.clear(). |
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:
@Transactional
, while called methods are.Configuration
Screenshots
(If applicable, add screenshots to help explain your problem.)
Environment (please complete the following information):
uname -a
orver
: Microsoft Windows [Version 10.0.19041.21]java -version
: 1.8Additional context
The reproducer is attached:
test-update2.zip
The text was updated successfully, but these errors were encountered: