-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
JPA entities containing LAZY loaded relations cannot be merged in another transaction #38807
Comments
I created a hibernate bug (though I'm not 100% sure it's not originating from Quarkus integration yet): https://hibernate.atlassian.net/browse/HHH-17750 |
Stack trace when GreetingResource:37 is uncommented in the reproducer:
|
Note: We noticed this error only occurs when the entity behind the lazy relation has a |
Thanks for taking a closer look. I have reproduced a similar error with just ORM; let's track the progress of this in the issue you've created in ORM JIRA. |
@marko-bekhta I think this issue is typically mitigated in various frameworks:
So I'm wondering: shouldn't Quarkus provide a similar mechanism? |
@ymajoros Feel free to open a feature request (or, more likely, link to an existing one), we can discuss that there. Though I need to mention that "Open session in view" is widely considered as an anti-pattern, so the discussion (and eventual solution) will have to address that. |
Good idea, I'll check out how to open a feature request if it's the way to go. It's considered an antipattern by Vlad, which doesn't make it widely accepted. It's the default in Spring, Wildfly and equivalently in the reference implementation (Eclipselink does it by default). It's an endless discussion, I'm well aware of the pro's and con's, but truth is: if you have more than 1 transaction and lazy relations, you will end up with the need to fetch them outside of the first transaction. Projections our (which basically comes down to eager fetching) isn't always the right solution for that. |
Should be fixed by #40230 |
Describe the bug
If I have 3 entities A,B,C; a relation in B
@JoinColumn(fetch = LAZY) A a
and a relation in C@JoinColumn B b
; thenIf I fetch B in a JTA tranacstion, then merge it (calling EntityManager::merge) in another transaction, I get an error:
If I fetch C or A in a JTA transaction, then merge them in another one, it passes.
EDIT: The issue only occurs when the entity behind the lazy relation has a
@Version
field. In the reproducer, that would beEntityA#version
.The JPA spec states at https://jakarta.ee/specifications/persistence/3.0/jakarta-persistence-spec-3.0#merging-detached-entity-state:
However here it seems quarkus is not ignoring the
a
field inA
that is marked LAZY; and instead throws because the proxy does not contain the version value.EDIT: spec has a paragraph about version field in that section as well. However, if I understand correctly it applies to the detached entity being merged, not the one behind the lazy relation.
But If I merge a parent entity, like C, then it passes, and I can then merge B.
Expected behavior
I can fetch and merge JPA entities across tranasctions regarless of the columns FETCH type
Actual behavior
When I have an entity with a column maked with fetch type LAZY; I cannot merge it directly.
I would need to merge a parent entity to obtain a managed instance.
How to Reproduce?
The https://github.com/cghislai/quarkus-merge-lazy contains a reproducer test.
Output of
uname -a
orver
No response
Output of
java -version
No response
Quarkus version or git rev
No response
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: