From 1c955c83b6e08518cb68673496833fb45a18c356 Mon Sep 17 00:00:00 2001 From: Vincent Bouthinon Date: Wed, 29 Oct 2025 11:48:11 +0100 Subject: [PATCH 1/3] HHH-19899 : [Reproducer test] Proxy generation fails with @ConcreteProxy and sealed abstract entities --- .../ConcreteProxyWithSealedClassesTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java new file mode 100644 index 000000000000..691ea26c0529 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java @@ -0,0 +1,57 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.proxy.concrete; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; +import org.junit.jupiter.api.Test; + +/** + * Tests the compatibility of Hibernate {@code @ConcreteProxy} with Java {@code sealed} + * inheritance hierarchies. Proxy generation may fail during {@code SessionFactory} + * bootstrap if the abstract sealed root cannot be subclassed at runtime. These tests + * document the limitation and assert the expected failure behavior. + * + * @author Vincent Bouthinon + */ +@Jpa( + annotatedClasses = {ConcreteProxyWithSealedClassesTest.Actor.class}, + integrationSettings = { + @Setting(name = org.hibernate.cfg.AvailableSettings.SHOW_SQL, value = "true"), + } +) +@JiraKey("HHH-19899") +class ConcreteProxyWithSealedClassesTest { + + @Test + void testConcreteProxyWithSealedClassesTest(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + Actor actor = new Postman(); + entityManager.persist( actor ); + entityManager.flush(); + } + ); + } + + @Entity(name = "actor") + @Table(name = "actor") + public static abstract sealed class Actor { + @Id + @GeneratedValue + private Long id; + } + + @Entity(name = "Postman") + @Table(name = "Postman") + public static non-sealed class Postman extends Actor { + } +} From c8ced5f85fda56ee1c5c581b8a85b33354478481 Mon Sep 17 00:00:00 2001 From: Vincent Bouthinon Date: Wed, 29 Oct 2025 12:01:41 +0100 Subject: [PATCH 2/3] HHH-19899 : [Reproducer test] Add @ConcreteProxy Caused by: java.lang.IncompatibleClassChangeError: class org.hibernate.orm.test.proxy.concrete.ConcreteProxyWithSealedClassesTest$Actor$HibernateProxy cannot inherit from sealed class org.hibernate.orm.test.proxy.concrete.ConcreteProxyWithSealedClassesTest$Actor --- .../proxy/concrete/ConcreteProxyWithSealedClassesTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java index 691ea26c0529..f073898ae893 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java @@ -8,6 +8,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.Table; +import org.hibernate.annotations.ConcreteProxy; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.Jpa; @@ -44,6 +45,7 @@ void testConcreteProxyWithSealedClassesTest(EntityManagerFactoryScope scope) { @Entity(name = "actor") @Table(name = "actor") + @ConcreteProxy public static abstract sealed class Actor { @Id @GeneratedValue @@ -52,6 +54,7 @@ public static abstract sealed class Actor { @Entity(name = "Postman") @Table(name = "Postman") + @ConcreteProxy public static non-sealed class Postman extends Actor { } } From 9089d5a6b0c7f7020efe7a98f0f94a62eb76a6c5 Mon Sep 17 00:00:00 2001 From: Vincent Bouthinon Date: Wed, 29 Oct 2025 12:02:58 +0100 Subject: [PATCH 3/3] HHH-19899 : [Reproducer test] Add @ConcreteProxy Caused by: java.lang.IncompatibleClassChangeError: class org.hibernate.orm.test.proxy.concrete.ConcreteProxyWithSealedClassesTest$Actor$HibernateProxy cannot inherit from sealed class org.hibernate.orm.test.proxy.concrete.ConcreteProxyWithSealedClassesTest$Actor --- .../test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java index f073898ae893..4039411ed1ca 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/concrete/ConcreteProxyWithSealedClassesTest.java @@ -54,7 +54,6 @@ public static abstract sealed class Actor { @Entity(name = "Postman") @Table(name = "Postman") - @ConcreteProxy public static non-sealed class Postman extends Actor { } }