[JIRA] (HHH-16832) Bytecode enhancement leads to broken constructor for a generic embedded field in a MappedSuperclass
by Yoann Rodière (JIRA)
Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNmE5MDE5YWZl... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16832?atlOrigin=eyJpIjoiNmE5MD... ) HHH-16832 ( https://hibernate.atlassian.net/browse/HHH-16832?atlOrigin=eyJpIjoiNmE5MD... ) Bytecode enhancement leads to broken constructor for a generic embedded field in a MappedSuperclass ( https://hibernate.atlassian.net/browse/HHH-16832?atlOrigin=eyJpIjoiNmE5MD... )
Issue Type: Bug Affects Versions: 6.2.5 Assignee: Unassigned Components: hibernate-core Created: 21/Jun/2023 03:34 AM Priority: Major Reporter: Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Affects ORM 6.3 (current main) and 6.2.5, at least. I think 6.2.4 and below were a bit less affected, because they didn’t detect composite fields correctly (see HHH-16774 ( https://hibernate.atlassian.net/browse/HHH-16774 ) Closed ), so one might not have noticed when using e.g. @EmbeddedId , but the bug was already there when using @Embedded.
With the following model, one will get this exception when calling MyEntity ’s constructor:
java.lang.NoSuchMethodError: 'org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest$MyEmbeddable org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.MyNonVisibleGenericMappedSuperclass.$$_hibernate_read_embedded()'
at org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest$MyEntity.$$_hibernate_write_embedded(DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest.java)
at org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.MyNonVisibleGenericMappedSuperclass.setEmbedded(MyNonVisibleGenericMappedSuperclass.java:25)
at org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest$MyEntity.<init>(DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest.java:175)
at org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest.shouldCreateTheTracker(DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest.java:90)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
Model:
@Embeddable
public class MyEmbeddable {
@Column
private String text;
public MyEmbeddable() {
}
private MyEmbeddable(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
@Entity(name = "myentity")
public class MyEntity extends MyNonVisibleGenericMappedSuperclass<MyEmbeddable> {
@Id
private Integer id;
public MyEntity() {
}
private MyEntity(Integer id, String text) {
this.id = id;
setEmbedded( new MyEmbeddable( text ) );
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
// This class must not be nested in the test class, otherwise its private fields will be visible
// from subclasses and we won't reproduce the bug.
@MappedSuperclass
public abstract class MyNonVisibleGenericMappedSuperclass<C> {
@Embedded
private C embedded;
public C getEmbedded() {
return embedded;
}
public void setEmbedded(C embedded) {
this.embedded = embedded;
}
}
The bug also affects @EmbeddedId , but that seems irrelevant.
I will submit a PR with a reproducer ASAP.
( https://hibernate.atlassian.net/browse/HHH-16832#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16832#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100227- sha1:28a616e )
1 year, 6 months