Oliver Drotbohm (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ed8acf...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOGU5NDAyZDg4...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15552?atlOrigin=eyJpIjoiOGU5ND...
) HHH-15552 (
https://hibernate.atlassian.net/browse/HHH-15552?atlOrigin=eyJpIjoiOGU5ND...
) Embeddable type cannot be cast to org.hibernate.usertype.CompositeUserType if referred
to from a mapped superclass with generic parameter (
https://hibernate.atlassian.net/browse/HHH-15552?atlOrigin=eyJpIjoiOGU5ND...
)
Issue Type: Bug Affects Versions: 6.1.3 Assignee: Unassigned Components:
hibernate-entitymanager Created: 26/Sep/2022 06:05 AM Priority: Major Reporter: Oliver
Drotbohm (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ed8acf...
)
Trying to upgrade a project from Hibernate 5 to 6 I run into the following issue:
class ….MyEmbeddable cannot be cast to class org.hibernate.usertype.CompositeUserType
(….MyEmbeddable and org.hibernate.usertype.CompositeUserType are in unnamed module of
loader 'app')
at org.hibernate.type.ComponentType.<init>(ComponentType.java:113)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at org.hibernate.mapping.Component.getType(Component.java:255)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at
org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:375)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at
org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:111)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at
org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:96)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:331)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at
org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.processJpa(JpaMetamodelImpl.java:504)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at
org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:244)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at
org.hibernate.metamodel.internal.RuntimeMetamodelsImpl.finishInitialization(RuntimeMetamodelsImpl.java:60)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:308)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at
org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:415)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1425)
~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
The rough arrangement looks like this (pseudocode):
@Embeddable
class MyEmbeddable { }
@MappedSuperclass
class SuperType<T> {
MyEmbeddable embeddable;
}
@Entity
class ConcreteType<T> extends SuperType<T> { }
org.hibernate.cfg.ClassPropertyHolder.addPropertyToMappedSuperclass(Property, XClass) runs
into a special branch of the code if the mapped superclass has generic parameters. In that
case, it ultimately ends up calling setTypeName(…) with the type name of the embeddable as
parameter. ComponentType later inspects that type name and tries to resolve it in its
constructor, unconditionally casting it to CompositeUserType.
Find a reproducer here (
https://github.com/odrotbohm/hibernate-bugs/tree/main/generic-mapped-supe... ).
$ git clone
https://github.com/odrotbohm/hibernate-bugs
$ cd hibernate-bugs/generic-mapped-superclass
$ mvn clean test // works, Hibernate 5
$ mvn clean test -Phibernate-6 // fails as described above, Hibernate 6.1.3
Hope that helps further diagnosing the problem.
(
https://hibernate.atlassian.net/browse/HHH-15552#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15552#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:1c92a42 )