From 92e29b63dbd689103ccfa2ae636ce927718ee8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Cedomir=20Igaly?= Date: Mon, 16 Dec 2024 13:02:46 +0100 Subject: [PATCH] HHH-18945 Test case - entity class extends mapped superclass with same simple class name --- .../ClassNameCollisionTest.java | 34 +++++++++++++++++++ .../test/classnamecollision/Something.java | 12 +++++++ .../somewhere/Something.java | 12 +++++++ 3 files changed, 58 insertions(+) create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/ClassNameCollisionTest.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/Something.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/somewhere/Something.java diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/ClassNameCollisionTest.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/ClassNameCollisionTest.java new file mode 100644 index 0000000000..d0c8343fca --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/ClassNameCollisionTest.java @@ -0,0 +1,34 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.processor.test.classnamecollision; + +import org.hibernate.processor.test.util.CompilationTest; +import org.hibernate.processor.test.util.WithClasses; +import org.junit.Test; + +import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor; +import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString; +import static org.hibernate.processor.test.util.TestUtil.getMetamodelClassFor; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ClassNameCollisionTest extends CompilationTest { + + @Test + @WithClasses({ + Something.class, + org.hibernate.processor.test.classnamecollision.somewhere.Something.class + }) + public void testAmbiguousSimpleName() { + System.out.println( getMetaModelSourceAsString( Something.class ) ); + assertMetamodelClassGeneratedFor( Something.class ); + System.out.println( getMetaModelSourceAsString( org.hibernate.processor.test.classnamecollision.somewhere.Something.class ) ); + assertMetamodelClassGeneratedFor( org.hibernate.processor.test.classnamecollision.somewhere.Something.class ); + assertEquals( + getMetamodelClassFor( org.hibernate.processor.test.classnamecollision.somewhere.Something.class ).getName(), + getMetamodelClassFor( Something.class ).getSuperclass() + .getName() ); + } + +} diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/Something.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/Something.java new file mode 100644 index 0000000000..c3eb936c21 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/Something.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.processor.test.classnamecollision; + +import jakarta.persistence.Entity; + +@Entity +public class Something extends org.hibernate.processor.test.classnamecollision.somewhere.Something { + String alphaValue; +} diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/somewhere/Something.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/somewhere/Something.java new file mode 100644 index 0000000000..be098a9558 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/classnamecollision/somewhere/Something.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.processor.test.classnamecollision.somewhere; + +import jakarta.persistence.MappedSuperclass; + +@MappedSuperclass +abstract public class Something { + String name; +}