diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index 8506a79245d6..16fb4704cd13 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -525,7 +525,8 @@ private ClassDetails idClassDetails(InheritanceState inheritanceState, ClassDeta if ( idClassAnn == null ) { try { // look for an Id class generated by Hibernate Processor as an inner class of static metamodel - final String generatedIdClassName = inheritanceState.getClassDetails().getClassName() + "_$Id"; + final Class javaClass = inheritanceState.getClassDetails().toJavaClass(); + final String generatedIdClassName = getGeneratedClassName( javaClass ) + "$Id"; return classDetailsRegistry.resolveClassDetails( generatedIdClassName ); } catch (RuntimeException e) { @@ -537,6 +538,12 @@ private ClassDetails idClassDetails(InheritanceState inheritanceState, ClassDeta } } + private static String getGeneratedClassName(Class javaClass) { + return javaClass.isMemberClass() + ? getGeneratedClassName( javaClass.getEnclosingClass() ) + "$" + javaClass.getSimpleName() + "_" + : javaClass.getName() + "_"; + } + private Component createMapperProperty( Map inheritanceStates, PersistentClass persistentClass, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaManyToOneLazyFetchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaManyToOneLazyFetchingTest.java index 242ae6a6461d..e070c1b5af06 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaManyToOneLazyFetchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaManyToOneLazyFetchingTest.java @@ -18,6 +18,7 @@ import org.hibernate.LazyInitializationException; import org.hibernate.annotations.JoinColumnOrFormula; import org.hibernate.annotations.JoinFormula; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey; @@ -29,6 +30,7 @@ import static org.junit.Assert.fail; @JiraKey(value = "HHH-12770") +@Exclude public class JoinFormulaManyToOneLazyFetchingTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaManyToOneNotIgnoreLazyFetchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaManyToOneNotIgnoreLazyFetchingTest.java index 6c0fd92b1117..06a45890ad58 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaManyToOneNotIgnoreLazyFetchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaManyToOneNotIgnoreLazyFetchingTest.java @@ -12,6 +12,7 @@ import org.hibernate.annotations.JoinFormula; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.boot.model.internal.ToOneBinder; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; @@ -39,6 +40,7 @@ import static org.junit.Assert.assertNull; @JiraKey(value = "HHH-12770") +@Exclude public class JoinFormulaManyToOneNotIgnoreLazyFetchingTest extends BaseEntityManagerFunctionalTestCase { @Rule diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaOneToOneNotIgnoreLazyFetchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaOneToOneNotIgnoreLazyFetchingTest.java index 46d2adbd7a93..4b213977bcb8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaOneToOneNotIgnoreLazyFetchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/formula/JoinFormulaOneToOneNotIgnoreLazyFetchingTest.java @@ -12,6 +12,7 @@ import org.hibernate.annotations.JoinFormula; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.boot.model.internal.ToOneBinder; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; @@ -39,6 +40,7 @@ import static org.junit.Assert.assertNull; @JiraKey(value = "HHH-12770") +@Exclude public class JoinFormulaOneToOneNotIgnoreLazyFetchingTest extends BaseEntityManagerFunctionalTestCase { @Rule diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/mapsid/NoIdClassMapsIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/mapsid/NoIdClassMapsIdTest.java index 9c8fc47c052f..778978d3ce62 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/mapsid/NoIdClassMapsIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/mapsid/NoIdClassMapsIdTest.java @@ -12,6 +12,7 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.MapsId; import jakarta.persistence.OneToMany; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; @@ -82,6 +83,7 @@ static class Loan { @Entity(name = "Extension") + @Exclude static class Extension { @Id private Long exLoanId; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/associations/CompositeIdAssociationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/associations/CompositeIdAssociationTest.java index 58a2dffce3b1..c772a57d6c2a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/associations/CompositeIdAssociationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/associations/CompositeIdAssociationTest.java @@ -13,6 +13,7 @@ import jakarta.persistence.ManyToOne; import org.hibernate.annotations.NaturalId; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.junit.Test; @@ -22,6 +23,7 @@ /** * @author Vlad Mihalcea */ +@Exclude public class CompositeIdAssociationTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/component/StructComponentManyToOneCompositeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/component/StructComponentManyToOneCompositeTest.java index b7f613bd646f..3caaa33662a2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/component/StructComponentManyToOneCompositeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/component/StructComponentManyToOneCompositeTest.java @@ -11,6 +11,7 @@ import jakarta.persistence.ManyToOne; import org.hibernate.Hibernate; import org.hibernate.annotations.Struct; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; @@ -37,6 +38,7 @@ ) @SessionFactory @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsStructAggregate.class) +@Exclude public class StructComponentManyToOneCompositeTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/ecid/CompositeIdAssociationsWithEmbeddedCompositeIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/ecid/CompositeIdAssociationsWithEmbeddedCompositeIdTest.java index dc727a29b39e..59d2ef595889 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/ecid/CompositeIdAssociationsWithEmbeddedCompositeIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/ecid/CompositeIdAssociationsWithEmbeddedCompositeIdTest.java @@ -12,6 +12,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; @@ -33,6 +34,7 @@ } ) @SessionFactory +@Exclude public class CompositeIdAssociationsWithEmbeddedCompositeIdTest { @AfterEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/hhh18829/AutoGeneratedIdClassTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/hhh18829/AutoGeneratedIdClassTest.java index 2a75a72a86a7..ef4255be6ff7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/hhh18829/AutoGeneratedIdClassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/hhh18829/AutoGeneratedIdClassTest.java @@ -4,6 +4,8 @@ */ package org.hibernate.orm.test.mapping.hhh18829; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.SessionFactory; @@ -15,7 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -@DomainModel(annotatedClasses = EmployeeWithoutIdClass.class) +@DomainModel(annotatedClasses = {EmployeeWithoutIdClass.class, AutoGeneratedIdClassTest.Inner.class}) @JiraKey(" HHH-18829") @SessionFactory public class AutoGeneratedIdClassTest { @@ -35,6 +37,19 @@ void setUp(SessionFactoryScope sessionFactoryScope) { two.address = "1600 Pennsylvania Avenue"; sess.persist( two ); } ); + sessionFactoryScope.inTransaction( sess -> { + final var one = new Inner(); + one.empName = "John Doe"; + one.empId = 1; + one.address = "10 Downing Street, SW1A 2AA"; + sess.persist( one ); + + final var two = new Inner(); + two.empName = "Dave Default"; + two.empId = 13; + two.address = "1600 Pennsylvania Avenue"; + sess.persist( two ); + } ); } @Test @@ -43,10 +58,30 @@ public void test(SessionFactoryScope sessionFactoryScope) final var idClass = Class.forName( EmployeeWithoutIdClass.class.getName() + "_$Id" ); final var id = idClass.getConstructors()[0].newInstance( "John Doe", 1 ); final var employees = sessionFactoryScope.fromSession( - sess -> sess.createQuery( "from EmployeeWithoutIdClass where id=:id", EmployeeWithoutIdClass.class ).setParameter( "id", id ) + sess -> sess.createQuery( "from EmployeeWithoutIdClass where id=:id", EmployeeWithoutIdClass.class ) + .setParameter( "id", id ) .getResultList() ); assertEquals( 1, employees.size() ); assertEquals( "10 Downing Street, SW1A 2AA", employees.get( 0 ).address ); } + + @Test + public void innerEntityClassTest(SessionFactoryScope sessionFactoryScope) + throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException { + final var idClass = Class.forName( AutoGeneratedIdClassTest .class.getName() + "_$Inner_$Id" ); + final var id = idClass.getConstructors()[0].newInstance( "Dave Default", 13 ); + final Inner employee = sessionFactoryScope.fromSession( + sess -> sess.find( Inner.class, id ) ); + assertEquals( "1600 Pennsylvania Avenue", employee.address ); + } + + @Entity + static class Inner { + @Id + String empName; + @Id + Integer empId; + String address; + } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/IdManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/IdManyToOneTest.java index 407b82707f33..2d4782172059 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/IdManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/IdManyToOneTest.java @@ -11,6 +11,7 @@ import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.junit.Test; @@ -21,6 +22,7 @@ /** * @author Vlad Mihalcea */ +@Exclude public class IdManyToOneTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MultipleIdRelatedIdQueryTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MultipleIdRelatedIdQueryTest.java index 75b3e96a986a..e2e3c5ccc352 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MultipleIdRelatedIdQueryTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MultipleIdRelatedIdQueryTest.java @@ -12,6 +12,7 @@ import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; +import org.hibernate.annotations.processing.Exclude; import org.hibernate.envers.Audited; import org.hibernate.envers.RevisionType; import org.hibernate.envers.query.AuditEntity; @@ -29,6 +30,7 @@ * @author Chris Cranford */ @JiraKey(value = "HHH-11748") +@Exclude public class MultipleIdRelatedIdQueryTest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/AutoGeneratedIdClassTest.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/AutoGeneratedIdClassTest.java index edc1d205923c..aaeeba8cc91d 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/AutoGeneratedIdClassTest.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/AutoGeneratedIdClassTest.java @@ -38,6 +38,18 @@ public void test() { "EmployeeWithIdClass_ should not have inner class Id" ); } + @Test + @WithClasses(value = {Outer.Inner.class, Outer.Super.class}) + @TestForIssue(jiraKey = "HHH-18829") + public void testInner() { + System.out.println( TestUtil.getMetaModelSourceAsString( Outer.class ) ); + System.out.println( TestUtil.getMetaModelSourceAsString( Outer.Inner.class ) ); + System.out.println( TestUtil.getMetaModelSourceAsString( Outer.Super.class ) ); + + checkIfIdClassIsGenerated( Outer.Inner.class, new String[] {"empName", "empId"} ); + checkIfIdClassIsGenerated( Outer.Super.class, new String[] {"empName", "empId"} ); + } + private static void checkIfIdClassIsGenerated(Class entityClass, String[] idComponentNames) { final var clazz = getMetamodelClassFor( entityClass ); final var maybeIdClass = Arrays.stream( clazz.getClasses() ) diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/Outer.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/Outer.java new file mode 100644 index 000000000000..2a627fd89162 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/Outer.java @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.processor.test.hhh18829; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; + +public class Outer { + + @Entity + static class Inner { + @Id + String empName; + @Id + Integer empId; + String address; + } + + @MappedSuperclass + static class Super { + @Id + String empName; + @Id + Integer empId; + String address; + } +}