-
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
Hibernate bytecode enhancement applied by quarkus generates invalid bytecode for embeddedId value objects #20186
Comments
Thanks for reporting! @Sanne this looks like an issue in Hibernate itself, not Quarkus. Correct? |
@geoand Quarkus does its own bytecode enhancement on Hibernate ORM entities too, so it might be either, or both. We need to investigate to be sure. I'd be inclined to blame Quarkus in this case, though. |
I'm not sure which one it would be; might be best to test in ORM upstream first. |
Actually I didn't look at the reproducer close enough; the problem is caused by the property being I'm not sure Or am I just missing something? |
@yrodiere et al. thanks for looking into this :) The same thing (with ...
@Value(staticConstructor = "of")
public static class DrinkIdentifier implements Identifier {
String id;
}
... In the Spring-Restbucks example the following (decompiled) Java bytecode is generated for the @Embeddable
public static final class DrinkIdentifier implements Identifier, Serializable {
private final String id;
private DrinkIdentifier(String id) {
this.id = id;
}
public static DrinkIdentifier of(String id) {
return new DrinkIdentifier(id);
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof DrinkIdentifier))
return false;
DrinkIdentifier other = (DrinkIdentifier)o;
Object this$id = getId(), other$id = other.getId();
return !((this$id == null) ? (other$id != null) : !this$id.equals(other$id));
}
public int hashCode() {
int PRIME = 59;
result = 1;
Object $id = getId();
return result * 59 + (($id == null) ? 43 : $id.hashCode());
}
public String toString() {
return "Drink.DrinkIdentifier(id=" + getId() + ")";
}
public String getId() {
return this.id;
}
public DrinkIdentifier() {
this;
}
} this works well. |
yes it should be OK to have immutable identifiers - and in this case the embeddable component is the identifier. |
Confirmed as a bug in Hibernate ORM. Upstream ticket: https://hibernate.atlassian.net/browse/HHH-14828 I'll see how that can be fixed. |
hibernate/hibernate-orm#4231 should fix the problem. Once it's merged and released, we can upgrade Hibernate ORM in Quarkus and get the fix. |
Merged the fix, it will be in the next version: Thanks for the fix @yrodiere , and thanks @thomasdarimont for pointing it out! |
Thank you guys for the quick fix :) |
Describe the bug
Given the following JPA Entity class with an EmbeddedId class modeled as a value Object, the Hibernate bytecode enhancement that is triggered by Quarkus generates invalid bytecode (shown below). This leads to
java.lang.IllegalAccessError: Update to non-static final field com.example.Drink$DrinkId.id attempted from a different method ($$_hibernate_write_id) than the initializer method <init>
errors.Example class
Stacktrace:
The decompiled generated bytecode for the class
DrinkId
looks like this:Expected behavior
The hibernate bytecode enhancement applied by quarkus should not emit unnecessary / invalid change tracking bytecode.
Actual behavior
The hibernate bytecode enhancement applied by quarkus emits invalid bytecode which leads to errors at runtime.
How to Reproduce?
Output of
uname -a
orver
Linux neumann 5.13.14-200.fc34.x86_64 #1 SMP Fri Sep 3 15:33:01 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Output of
java -version
openjdk version "17" 2021-09-14 OpenJDK Runtime Environment (build 17+35-2724) OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.2.2.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Additional information
I'm not 100% sure if this is a quarkus issue or a plain hibernate issue.
The original example comes from a Spring Boot application (https://github.com/odrotbohm/spring-restbucks/blob/main/server/src/main/java/org/springsource/restbucks/drinks/Drink.java#L53) which uses Hibernate 5.5.6. In the spring app the bytecode of the
DrinkIdentifier
class is not enhanced.The quarkus version 2.2.2.Final seems to use Hibernate 5.5.7. Perhaps this is an hibernate issue that is
triggered by quarkus due to the explicit bytecode enhancement...
The text was updated successfully, but these errors were encountered: