[JIRA] (HHH-16166) ClassCastException, mixing mapping types for same field name on different entities
by Loukas Mouzos (JIRA)
Loukas Mouzos ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZmUzZTNjZDcy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16166?atlOrigin=eyJpIjoiZmUzZT... ) HHH-16166 ( https://hibernate.atlassian.net/browse/HHH-16166?atlOrigin=eyJpIjoiZmUzZT... ) ClassCastException, mixing mapping types for same field name on different entities ( https://hibernate.atlassian.net/browse/HHH-16166?atlOrigin=eyJpIjoiZmUzZT... )
Change By: Loukas Mouzos ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
We have a setup of a base entity which is inherited by many other entities. We use the inheritance type {{InheritanceType.JOINED}}.
In case the child entities have same field name but with a different type, a {{java.lang.ClassCastException}} is thrown during the initialization of the session factory (during post init callbacks):
{noformat}Caused by: java.lang.IllegalStateException: PostInitCallback queue could not be processed...
- PostInitCallbackEntry - Entity(model.BaseObj) `sqmMultiTableInsertStrategy` interpretation
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.executePostInitCallbacks(MappingModelCreationProcess.java:146)
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.execute(MappingModelCreationProcess.java:90)
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.process(MappingModelCreationProcess.java:39)
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:229)
at org.hibernate.metamodel.internal.RuntimeMetamodelsImpl.finishInitialization(RuntimeMetamodelsImpl.java:60)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:415)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:754)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:129)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:114)
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.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:203)
... 14 more
Suppressed: java.lang.ClassCastException: class org.hibernate.mapping.Set cannot be cast to class org.hibernate.mapping.SimpleValue (org.hibernate.mapping.Set and org.hibernate.mapping.SimpleValue are in unnamed module of loader 'app')
at org.hibernate.dialect.temptable.TemporaryTable.lambda$createEntityTable$4(TemporaryTable.java:340)
at java.base/java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:647)
at org.hibernate.persister.entity.AbstractEntityPersister.visitDeclaredAttributeMappings(AbstractEntityPersister.java:6135)
at org.hibernate.persister.entity.AbstractEntityPersister.visitSubTypeAttributeMappings(AbstractEntityPersister.java:6855)
at org.hibernate.dialect.temptable.TemporaryTable.lambda$createEntityTable$5(TemporaryTable.java:336)
at org.hibernate.dialect.temptable.TemporaryTable.<init>(TemporaryTable.java:145)
at org.hibernate.dialect.temptable.TemporaryTable.createEntityTable(TemporaryTable.java:250)
at org.hibernate.dialect.H2Dialect.getFallbackSqmInsertStrategy(H2Dialect.java:643)
at org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper.resolveInsertStrategy(SqmMutationStrategyHelper.java:87)
at org.hibernate.persister.entity.AbstractEntityPersister.interpretSqmMultiTableInsertStrategy(AbstractEntityPersister.java:5972)
at org.hibernate.persister.entity.AbstractEntityPersister.lambda$prepareMappingModel$12(AbstractEntityPersister.java:5825)
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess$PostInitCallbackEntry.process(MappingModelCreationProcess.java:210)
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.executePostInitCallbacks(MappingModelCreationProcess.java:108)
{noformat}
This is working with older Hibernate version {{5.6.14}} .
h3. Simple use case
BaseObj.java
{code:java}@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class BaseObj {
@Id
long id;
}{code}
Author.java
{code:java}@Entity
public class Author extends BaseObj {
String comments;
}{code}
Post.java
{code:java}@Entity
public class Post extends BaseObj {
@OneToMany(mappedBy = "post")
Set<Comment> comments;
}{code}
Comment.java
{code:java}@Entitypublic class Comment extends BaseObj {
@ManyToOne Post post;
}{code}
I have added a test case with the entities here [https://github.com/lmouzos/hibernate-test-case-templates|https://github.c...]
( https://hibernate.atlassian.net/browse/HHH-16166#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16166#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#100215- sha1:a0f3b6a )
1 year, 11 months
[JIRA] (HHH-16166) ClassCastException, mixing mapping types for same field name on different entities
by Loukas Mouzos (JIRA)
Loukas Mouzos ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMDY3ZjBkYzMz... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16166?atlOrigin=eyJpIjoiMDY3Zj... ) HHH-16166 ( https://hibernate.atlassian.net/browse/HHH-16166?atlOrigin=eyJpIjoiMDY3Zj... ) ClassCastException, mixing mapping types for same field name on different entities ( https://hibernate.atlassian.net/browse/HHH-16166?atlOrigin=eyJpIjoiMDY3Zj... )
Issue Type: Bug Affects Versions: 6.1.6 Assignee: Unassigned Components: hibernate-orm-modules Created: 10/Feb/2023 02:18 AM Environment: JVM: 17
Database: MSSQL
OS: Windows 10 enterprise x64 Priority: Blocker Reporter: Loukas Mouzos ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
We have a setup of a base entity which is inherited by many other entities. We use the inheritance type InheritanceType.JOINED.
In case the child entities have same field name but with a different type, a java.lang.ClassCastException is thrown during the initialization of the session factory (during post init callbacks):
Caused by: java.lang.IllegalStateException: PostInitCallback queue could not be processed...
- PostInitCallbackEntry - Entity(model.BaseObj) `sqmMultiTableInsertStrategy` interpretation
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.executePostInitCallbacks(MappingModelCreationProcess.java:146)
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.execute(MappingModelCreationProcess.java:90)
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.process(MappingModelCreationProcess.java:39)
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:229)
at org.hibernate.metamodel.internal.RuntimeMetamodelsImpl.finishInitialization(RuntimeMetamodelsImpl.java:60)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:415)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:754)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:129)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:114)
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.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:203)
... 14 more
Suppressed: java.lang.ClassCastException: class org.hibernate.mapping.Set cannot be cast to class org.hibernate.mapping.SimpleValue (org.hibernate.mapping.Set and org.hibernate.mapping.SimpleValue are in unnamed module of loader 'app')
at org.hibernate.dialect.temptable.TemporaryTable.lambda$createEntityTable$4(TemporaryTable.java:340)
at java.base/java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:647)
at org.hibernate.persister.entity.AbstractEntityPersister.visitDeclaredAttributeMappings(AbstractEntityPersister.java:6135)
at org.hibernate.persister.entity.AbstractEntityPersister.visitSubTypeAttributeMappings(AbstractEntityPersister.java:6855)
at org.hibernate.dialect.temptable.TemporaryTable.lambda$createEntityTable$5(TemporaryTable.java:336)
at org.hibernate.dialect.temptable.TemporaryTable.<init>(TemporaryTable.java:145)
at org.hibernate.dialect.temptable.TemporaryTable.createEntityTable(TemporaryTable.java:250)
at org.hibernate.dialect.H2Dialect.getFallbackSqmInsertStrategy(H2Dialect.java:643)
at org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper.resolveInsertStrategy(SqmMutationStrategyHelper.java:87)
at org.hibernate.persister.entity.AbstractEntityPersister.interpretSqmMultiTableInsertStrategy(AbstractEntityPersister.java:5972)
at org.hibernate.persister.entity.AbstractEntityPersister.lambda$prepareMappingModel$12(AbstractEntityPersister.java:5825)
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess$PostInitCallbackEntry.process(MappingModelCreationProcess.java:210)
at org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess.executePostInitCallbacks(MappingModelCreationProcess.java:108)
This is working with older Hibernate version 5.6.14.
Simple use case
---------------
BaseObj.java
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class BaseObj {
@Id
long id;
}
Author.java
@Entity
public class Author extends BaseObj {
String comments;
}
Post.java
@Entity
public class Post extends BaseObj {
@OneToMany(mappedBy = "post" )
Set<Comment> comments;
}
Comment.java
@Entitypublic class Comment extends BaseObj {
@ManyToOne Post post;
}
( https://hibernate.atlassian.net/browse/HHH-16166#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16166#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#100215- sha1:a0f3b6a )
1 year, 11 months