|
8 | 8 | import org.hibernate.annotations.NaturalId;
|
9 | 9 | import org.hibernate.graph.GraphSemantic;
|
10 | 10 | import org.hibernate.graph.RootGraph;
|
11 |
| -import org.hibernate.query.SelectionQuery; |
12 | 11 | import org.hibernate.testing.orm.junit.DomainModel;
|
13 | 12 | import org.hibernate.testing.orm.junit.SessionFactory;
|
14 | 13 | import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
|
19 | 18 | import java.util.Set;
|
20 | 19 |
|
21 | 20 | import static jakarta.persistence.FetchType.LAZY;
|
| 21 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
22 | 22 | import static org.hibernate.Hibernate.isInitialized;
|
23 | 23 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
24 | 24 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
@@ -173,7 +173,7 @@ public class NewGraphTest {
|
173 | 173 | }
|
174 | 174 |
|
175 | 175 | @Test
|
176 |
| - void subTypeEntityGraph(SessionFactoryScope scope) { |
| 176 | + void superTypeEntityGraph(SessionFactoryScope scope) { |
177 | 177 | scope.inTransaction( s -> {
|
178 | 178 | A a = new A();
|
179 | 179 | Aa aa = new Aa();
|
@@ -205,27 +205,29 @@ void subTypeEntityGraph(SessionFactoryScope scope) {
|
205 | 205 | .getSingleResult() );
|
206 | 206 | assertFalse( isInitialized( a.bs ) );
|
207 | 207 |
|
208 |
| - List<Aa> as = scope.fromSession( s -> { |
209 |
| - SelectionQuery<Aa> query = s.createSelectionQuery( "from Aa", Aa.class ); |
210 |
| - return query |
211 |
| - .setEntityGraph( query.getNamedEntityGraph( "a-graph" ), GraphSemantic.FETCH ) |
212 |
| - .getResultList(); |
213 |
| - } ); |
| 208 | + List<Aa> as = scope.fromSession( s -> s.createSelectionQuery( "from Aa", Aa.class ) |
| 209 | + .setNamedEntityGraph( "a-graph", GraphSemantic.FETCH ) |
| 210 | + .getResultList() ); |
214 | 211 | for ( Aa el : as ) {
|
215 | 212 | assertTrue( isInitialized( el.bs ) );
|
216 | 213 | assertFalse( isInitialized( el.bss ) );
|
217 | 214 | }
|
218 | 215 |
|
219 |
| - as = scope.fromSession( s -> { |
220 |
| - SelectionQuery<Aa> query = s.createSelectionQuery( "from Aa", Aa.class ); |
221 |
| - return query |
222 |
| - .setEntityGraph( query.getNamedEntityGraph( "aa-graph" ), GraphSemantic.FETCH ) |
223 |
| - .getResultList(); |
224 |
| - } ); |
| 216 | + as = scope.fromSession( s -> s.createSelectionQuery( "from Aa", Aa.class ) |
| 217 | + .setNamedEntityGraph( "aa-graph", GraphSemantic.FETCH ) |
| 218 | + .getResultList() ); |
225 | 219 | for ( Aa el : as ) {
|
226 | 220 | assertTrue( isInitialized( el.bs ) );
|
227 | 221 | assertTrue( isInitialized( el.bss ) );
|
228 | 222 | }
|
| 223 | + |
| 224 | + scope.inSession( s -> { |
| 225 | + assertThatThrownBy( () -> s.createSelectionQuery( "from Aa", Aa.class ) |
| 226 | + .setNamedEntityGraph( "i-do-not-exist-graph", GraphSemantic.FETCH ) |
| 227 | + .getResultList() ) |
| 228 | + .isInstanceOf( IllegalArgumentException.class ); |
| 229 | + } ); |
| 230 | + |
229 | 231 | }
|
230 | 232 |
|
231 | 233 | @Entity(name = "E")
|
@@ -273,8 +275,6 @@ static class A {
|
273 | 275 | @NamedEntityGraph(name = "aa-graph", attributeNodes = {@NamedAttributeNode("bs"), @NamedAttributeNode("bss"),})
|
274 | 276 | @Entity(name = "Aa")
|
275 | 277 | static class Aa extends A {
|
276 |
| - @Id @GeneratedValue |
277 |
| - Long id; |
278 | 278 |
|
279 | 279 | @OneToMany(mappedBy = "aa")
|
280 | 280 | Set<B> bss;
|
|
0 commit comments