-
Notifications
You must be signed in to change notification settings - Fork 582
4.x: Tests fail when upgrading to Hibernate 6.6.23.Final #10441 #10487
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
base: main
Are you sure you want to change the base?
Conversation
72419d5 to
cef1fa2
Compare
|
I want to be careful here; I think it should be possible to merge a detached entity according to the spec. Specifically, the spec says:
Then, recently, Hibernate says:
Indeed, merging a detached entity X when there is no "pre-existing managed entity instance X'" should result in an |
Thanks @ljnelson , does it make sense that you open them an issue to discuss this?. |
|
Native image fails consistently: |
5a51266 to
ad0497f
Compare
e23022b to
0d6d1a7
Compare
a3670af to
1a03467
Compare
…0441 Signed-off-by: Jorge Bescos Gascon <[email protected]>
|
It is passing now |
| ] | ||
| }, | ||
| { | ||
| "name": "org.hibernate.event.spi.PostUpsertEventListener[]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbescos such metadata should be unnecessary if you use the Hibernate provided GraalVM module?
-https://github.com/hibernate/hibernate-orm/blame/main/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java#L68
I created that module to simplify such integrations by other frameworks, please let us know if it's not useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file we tell GraalVM what classes should be available for reflection at runtime. I added that because GraalVM told me to do so.
We don't have org.hibernate.orm:hibernate-graalvm as dependency, but I have added it and the test fails, with and without this configuration. It compiles well, but in runtime I am having some ClassNotFoundExceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file we tell GraalVM what classes should be available for reflection at runtime. I added that because GraalVM told me to do so.
I understand, but it makes more sense to have the rules which are specific to a library to be maintained by the library - otherwise you'll need to make changes for each new Hibernate release.
So for that reason I had created the hibernate-graalvm module.
We don't have org.hibernate.orm:hibernate-graalvm as dependency, but I have added it and the test fails, with and without this configuration.
Such features need to be activated
| Args=-H:ReflectionConfigurationResources=${.}/reflect-config-additional.json | ||
| Args=-H:ReflectionConfigurationResources=${.}/reflect-config-additional.json \ | ||
| -H:ClassInitialization=org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext:run_time \ | ||
| -H:ClassInitialization=org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper:run_time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern would be that this is going to fail at runtime. Just hiding / postponing problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use static enhancement, so bytebuddy related things should not be executed. This args allows me to replace the static fields that are triggering reflection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand - but the compiler is usually right, it's running a formal proof. So if it's including it, this would suggest that there are some corner cases in which this code is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding --trace-class-initialization only shows the stack traces I printed here. It starts with ByteBuddyEnhancementContext and ByteBuddyProxyHelper. We cannot know more about why are that static fields loaded.
We already have a lot of GraalVM configuration related to Hibernate here and some other methods substitutions here. I was not part of this, but it seems this integration was not easy.
|
Kindly reminder to review this |
|
Next on my plate. Given @Sanne's comments and the change in tested behavior we may want to rethink how this all takes place. |
Well, it's not my bussiness now, but it's not the first time when I saw that Hibernate has issues to follow the spec. I have seen similar issues while merging an entity with Collection mapping in Hibernate 5 and 6. |
|
Hi @Tomas-Kraus, hope you're well. I will keep my opinions to myself. What I'm concerned about here specifically is that it seems that Hibernate does one thing and Eclipselink does another. There is a mechanism in our unit tests to account for this kind of divergence which happens in several other places if I remember right, where in the test you can say, well, if Eclipselink does this one thing and Hibernate does this other thing, pass the test, but at least in the test you can see that you had to account for the divergence. |
|
Hi @ljnelson, I'm fine and my relations with Oracle were always good so I can still at least tell what I know.
Now back to this issue: In Helidon Data there are few tests skipped with Hibernate. This is exactly what you are talking about. And another problem is caused by the previously mentioned merge on detached entity which, after being prosessed by Hibernate before, contains their PersistentBag as Collection. In this case, making clone of entity structure with Java default collections helps as workaround. And that's why my entity model in the tests, e.g. https://github.com/helidon-io/helidon/blob/main/data/tests/model/src/main/java/io/helidon/data/tests/model/Pokemon.java has clone methods. Anyway, spec says that merge shall work as UPSERT, i.e. merge state (update) or insert a new record, so you should push on Gavin to fix this. And https://javadoc.io/static/jakarta.persistence/jakarta.persistence-api/3.2.0/jakarta.persistence/jakarta/persistence/EntityManager.html#merge(java.lang.Object) javadoc says the same. Edit: And that's why I'm sad about Eclipselink, I have never seen issue like this there. |
|
Interesting. I was not talking about Helidon Data tests, though, just the stock container-managed JPA tests we have. Again, I would have to go back to refresh my memory but there are a few cases around JTA transactions where Hibernate does one thing and Eclipselink does another. We run the same tests through both providers and there is some mechanism for ensuring that you can at least see that the discrepancy is happening. I agree with you that the behavior for |
Description
Resolves #10441
Hibernate 6.6 cannot attach a removed entity:
https://docs.jboss.org/hibernate/orm/6.6/migration-guide/migration-guide.html#merge-versioned-deleted