Skip to content

Commit 44daf82

Browse files
Vincent Bouthinonyrodiere
authored andcommitted
HHH-19899 Test proxy generation with @ConcreteProxy and sealed abstract entities
1 parent 54f5844 commit 44daf82

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.proxy.concrete;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.GeneratedValue;
9+
import jakarta.persistence.Id;
10+
import jakarta.persistence.Inheritance;
11+
import jakarta.persistence.InheritanceType;
12+
import jakarta.persistence.Table;
13+
import org.hibernate.annotations.ConcreteProxy;
14+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
15+
import org.hibernate.testing.orm.junit.JiraKey;
16+
import org.hibernate.testing.orm.junit.Jpa;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
/**
22+
* Tests the compatibility of Hibernate {@code @ConcreteProxy} with Java {@code sealed}
23+
* inheritance hierarchies. Proxy generation may fail during {@code SessionFactory}
24+
* bootstrap if the abstract sealed root cannot be subclassed at runtime. These tests
25+
* document the limitation and assert the expected failure behavior.
26+
*
27+
* @author Vincent Bouthinon
28+
*/
29+
@Jpa(annotatedClasses = {ConcreteProxyWithSealedClassesTest.Actor.class, ConcreteProxyWithSealedClassesTest.Postman.class})
30+
@JiraKey("HHH-19899")
31+
class ConcreteProxyWithSealedClassesTest {
32+
33+
@Test
34+
void testConcreteProxyWithSealedClassesTest(EntityManagerFactoryScope scope) {
35+
var id = scope.fromTransaction( entityManager -> {
36+
Actor actor = new Postman();
37+
entityManager.persist( actor );
38+
return actor.id;
39+
} );
40+
scope.inTransaction( entityManager -> {
41+
Actor actor = entityManager.getReference( Actor.class, id );
42+
assertThat( actor ).isInstanceOf( Postman.class );
43+
} );
44+
}
45+
46+
@Entity(name = "actor")
47+
@Table(name = "actor")
48+
@ConcreteProxy
49+
public static abstract sealed class Actor {
50+
@Id
51+
@GeneratedValue
52+
private Long id;
53+
}
54+
55+
@Entity(name = "Postman")
56+
public static non-sealed class Postman extends Actor {
57+
}
58+
}

0 commit comments

Comments
 (0)