From 2076fc09765a492bf728aee97a8e923c9a671782 Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Tue, 20 Jun 2023 01:04:10 +0200 Subject: [PATCH] HHH-16711 / HHH-16707 - Added tests for these related issues Signed-off-by: Jan Schatteman --- .../test/inheritance/hhh16711/Inheriting.java | 24 +++++++ .../MappedSuperclassInheritanceTest.java | 65 +++++++++++++++++++ .../hhh16711/otherPackage/Inherited.java | 41 ++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/Inheriting.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/MappedSuperclassInheritanceTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/otherPackage/Inherited.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/Inheriting.java b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/Inheriting.java new file mode 100644 index 0000000000..51c02cdd4a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/Inheriting.java @@ -0,0 +1,24 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.inheritance.hhh16711; + +import org.hibernate.orm.test.inheritance.hhh16711.otherPackage.Inherited; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "inheriting") +class Inheriting extends Inherited { + + Inheriting(String id, String name) { + super(id, name); + } + + Inheriting() { + } +} \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/MappedSuperclassInheritanceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/MappedSuperclassInheritanceTest.java new file mode 100644 index 0000000000..1ac45d5589 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/MappedSuperclassInheritanceTest.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.orm.test.inheritance.hhh16711; + +import java.util.List; + +import org.hibernate.orm.test.inheritance.hhh16711.otherPackage.Inherited; +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.Jpa; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Jpa( + annotatedClasses = { + Inheriting.class, + Inherited.class + } +) +public class MappedSuperclassInheritanceTest { + + @AfterEach + public void cleanup(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> entityManager.createQuery( "delete from Inheriting" ).executeUpdate() + ); + } + + @Test + @JiraKey( value = "HHH-16707") + public void testNew(EntityManagerFactoryScope scope) { + scope.inTransaction(entityManager -> { + Inheriting inheriting = new Inheriting("myId", "myName"); + entityManager.persist( inheriting ); + }); + + scope.inTransaction(entityManager -> { + List results = entityManager.createQuery( "SELECT i.id, i.name FROM Inheriting i", Object[].class).getResultList(); + assertEquals( 1, results.size() ); + assertEquals( "myId", results.get(0)[0].toString() ); + assertEquals( "myName", results.get(0)[1].toString() ); + }); + } + + @Test + @JiraKey( value = "HHH-16711") + public void testSelect(EntityManagerFactoryScope scope) { + scope.inTransaction(entityManager -> { + entityManager.createNativeQuery("INSERT INTO inheriting VALUES ('myId', 'myName')").executeUpdate(); + }); + + scope.inTransaction(entityManager -> { + List results = entityManager.createQuery( "SELECT i FROM Inheriting i", Inheriting.class).getResultList(); + assertEquals( 1, results.size() ); + }); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/otherPackage/Inherited.java b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/otherPackage/Inherited.java new file mode 100644 index 0000000000..a9e3450e82 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/hhh16711/otherPackage/Inherited.java @@ -0,0 +1,41 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.inheritance.hhh16711.otherPackage; + +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; + +@MappedSuperclass +public abstract class Inherited { + @Id + protected String id; + protected String name; + + protected Inherited(String id, String name) { + this.id = id; + this.name = name; + } + + protected Inherited() { + } + + protected String getId() { + return id; + } + + protected String getName() { + return name; + } + + protected void setId(String id) { + this.id = id; + } + + protected void setName(String name) { + this.name = name; + } +} \ No newline at end of file