|
4 | 4 | */
|
5 | 5 | package org.hibernate.orm.test.entitygraph;
|
6 | 6 |
|
7 |
| -import java.util.Collection; |
8 | 7 | import java.util.Date;
|
9 | 8 | import java.util.List;
|
10 |
| -import jakarta.persistence.AttributeNode; |
| 9 | + |
11 | 10 | import jakarta.persistence.Entity;
|
12 | 11 | import jakarta.persistence.EntityGraph;
|
13 | 12 | import jakarta.persistence.EntityManager;
|
|
21 | 20 | import jakarta.persistence.Temporal;
|
22 | 21 | import jakarta.persistence.TemporalType;
|
23 | 22 | import jakarta.persistence.TypedQuery;
|
24 |
| -import jakarta.persistence.metamodel.Attribute; |
25 |
| -import jakarta.persistence.metamodel.EntityType; |
26 | 23 |
|
27 | 24 | import org.hibernate.graph.GraphSemantic;
|
28 | 25 |
|
|
32 | 29 | import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
33 | 30 | import org.junit.jupiter.api.Test;
|
34 | 31 |
|
35 |
| -import static org.hamcrest.CoreMatchers.is; |
36 | 32 | import static org.hamcrest.MatcherAssert.assertThat;
|
37 |
| -import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize; |
38 | 33 | import static org.hibernate.testing.hamcrest.InitializationCheckMatcher.isInitialized;
|
39 | 34 |
|
40 | 35 | /**
|
@@ -143,68 +138,6 @@ void fetchAttributeNodeByStringFromSubgraph(SessionFactoryScope scope) {
|
143 | 138 | query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph );
|
144 | 139 | final List<CustomerOrder> results = query.getResultList();
|
145 | 140 |
|
146 |
| - assertEntityGraph( entityGraph ); |
147 |
| - assertThat( results, isInitialized() ); |
148 |
| - } |
149 |
| - ); |
150 |
| - } |
151 |
| - |
152 |
| - @Test |
153 |
| - @JiraKey( value = "HHH-13233") |
154 |
| - @SuppressWarnings({ "unchecked", "rawtypes" }) |
155 |
| - void fetchAttributeNodeByAttributeFromSubgraph(SessionFactoryScope scope) { |
156 |
| - scope.inTransaction( |
157 |
| - session -> { |
158 |
| - Address address = new Address(); |
159 |
| - address.city = "TestCity"; |
160 |
| - |
161 |
| - CustomerOrder customerOrder = new CustomerOrder(); |
162 |
| - customerOrder.shippingAddress = address; |
163 |
| - |
164 |
| - Product product = new Product(); |
165 |
| - |
166 |
| - OrderPosition orderPosition = new OrderPosition(); |
167 |
| - orderPosition.product = product; |
168 |
| - |
169 |
| - customerOrder.orderPosition = orderPosition; |
170 |
| - session.persist( address ); |
171 |
| - session.persist( orderPosition ); |
172 |
| - session.persist( product ); |
173 |
| - session.persist( customerOrder ); |
174 |
| - } |
175 |
| - ); |
176 |
| - |
177 |
| - scope.inTransaction( |
178 |
| - session -> { |
179 |
| - final EntityManager em = session.unwrap( EntityManager.class ); |
180 |
| - final EntityGraph<CustomerOrder> entityGraph = em.createEntityGraph( CustomerOrder.class ); |
181 |
| - EntityType<CustomerOrder> customerOrderEntityType = |
182 |
| - scope.getSessionFactory().getMetamodel().entity( CustomerOrder.class ); |
183 |
| - entityGraph.addAttributeNodes( |
184 |
| - customerOrderEntityType.getAttribute( "shippingAddress" ), |
185 |
| - customerOrderEntityType.getAttribute( "orderDate" ) |
186 |
| - ); |
187 |
| - entityGraph.addAttributeNodes( customerOrderEntityType.getAttribute( "shippingAddress" ) ); |
188 |
| - |
189 |
| - final Subgraph<OrderPosition> orderProductsSubgraph = |
190 |
| - entityGraph.addSubgraph( (Attribute) customerOrderEntityType.getAttribute( "orderPosition" ) ); |
191 |
| - EntityType<OrderPosition> positionEntityType = |
192 |
| - scope.getSessionFactory().getMetamodel().entity( OrderPosition.class ); |
193 |
| - orderProductsSubgraph.addAttributeNodes( positionEntityType.getAttribute( "amount" ) ); |
194 |
| - orderProductsSubgraph.addAttributeNodes( positionEntityType.getAttribute( "product" ) ); |
195 |
| - |
196 |
| - final Subgraph<Product> productSubgraph = |
197 |
| - orderProductsSubgraph.addSubgraph( (Attribute) positionEntityType.getAttribute( "product" ) ); |
198 |
| - EntityType<Product> productEntityType = scope.getSessionFactory().getMetamodel().entity( Product.class ); |
199 |
| - productSubgraph.addAttributeNodes( productEntityType.getAttribute( "productName" ) ); |
200 |
| - |
201 |
| - TypedQuery<CustomerOrder> query = em.createQuery( |
202 |
| - "SELECT o FROM CustomerOrder o", CustomerOrder.class |
203 |
| - ); |
204 |
| - query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph ); |
205 |
| - final List<CustomerOrder> results = query.getResultList(); |
206 |
| - |
207 |
| - assertEntityGraph( entityGraph ); |
208 | 141 | assertThat( results, isInitialized() );
|
209 | 142 | }
|
210 | 143 | );
|
@@ -250,37 +183,6 @@ void fetchUsingHql(SessionFactoryScope scope) {
|
250 | 183 | );
|
251 | 184 | }
|
252 | 185 |
|
253 |
| - /** |
254 |
| - * Verify that entityGraph has expected state |
255 |
| - * |
256 |
| - * customerOrder - shippingAddress |
257 |
| - * - orderDate |
258 |
| - * - orderPosition - amount |
259 |
| - * - product - productName |
260 |
| - * |
261 |
| - * @param entityGraph entityGraph |
262 |
| - */ |
263 |
| - private void assertEntityGraph(EntityGraph<CustomerOrder> entityGraph) { |
264 |
| - assertThat(entityGraph.getAttributeNodes(), hasSize( 3 ) ); |
265 |
| - for ( AttributeNode<?> entityGraphAttributeNode : entityGraph.getAttributeNodes() ) { |
266 |
| - if ( "orderPosition".equals( entityGraphAttributeNode.getAttributeName() ) ) { |
267 |
| - Collection<Subgraph> orderPositionGraph = entityGraphAttributeNode.getSubgraphs().values(); |
268 |
| - assertThat( orderPositionGraph, hasSize( 1 ) ); |
269 |
| - List<AttributeNode<?>> orderPositionAttributes = orderPositionGraph.iterator().next().getAttributeNodes(); |
270 |
| - assertThat( orderPositionAttributes, hasSize( 2 ) ); |
271 |
| - for ( AttributeNode<?> orderPositionAttributeNode : orderPositionAttributes ) { |
272 |
| - if ( "product".equals( orderPositionAttributeNode.getAttributeName() ) ) { |
273 |
| - assertThat( orderPositionAttributeNode.getSubgraphs().entrySet(), hasSize( 1 ) ); |
274 |
| - } else { |
275 |
| - assertThat( orderPositionAttributeNode.getSubgraphs().isEmpty(), is( true ) ); |
276 |
| - } |
277 |
| - } |
278 |
| - } else { |
279 |
| - assertThat( entityGraphAttributeNode.getSubgraphs().isEmpty(), is( true ) ); |
280 |
| - } |
281 |
| - } |
282 |
| - } |
283 |
| - |
284 | 186 | @Entity(name = "CustomerOrder")
|
285 | 187 | @Table(name = "customerOrder")
|
286 | 188 | public static class CustomerOrder {
|
|
0 commit comments