|
21 | 21 | import jakarta.persistence.ElementCollection; |
22 | 22 | import jakarta.persistence.Embeddable; |
23 | 23 | import jakarta.persistence.Embedded; |
| 24 | +import jakarta.persistence.Entity; |
24 | 25 | import jakarta.persistence.EntityManager; |
25 | 26 | import jakarta.persistence.Id; |
26 | 27 | import jakarta.persistence.ManyToOne; |
@@ -77,8 +78,8 @@ class JpaQueryCreatorTests { |
77 | 78 |
|
78 | 79 | static List<JpqlQueryTemplates> ignoreCaseTemplates = List.of(JpqlQueryTemplates.LOWER, JpqlQueryTemplates.UPPER); |
79 | 80 |
|
80 | | - private static final TestMetaModel ORDER_WITH_RELATIONS = TestMetaModel.hibernateModel( |
81 | | - OrderWithRelations.class, Customer.class, Supplier.class); |
| 81 | + private static final TestMetaModel ORDER_WITH_RELATIONS = TestMetaModel.hibernateModel(OrderWithRelations.class, |
| 82 | + Customer.class, Supplier.class); |
82 | 83 |
|
83 | 84 | @Test // GH-3588 |
84 | 85 | void simpleProperty() { |
@@ -249,9 +250,8 @@ void simplePropertyMixedCase(JpqlQueryTemplates ignoreCaseTemplate) { |
249 | 250 | .withParameters("spring", "data") // |
250 | 251 | .as(QueryCreatorTester::create) // |
251 | 252 | .expectJpql("SELECT p FROM %s p WHERE p.name = ?1 AND %s(p.productType) = %s(?2)", |
252 | | - DefaultJpaEntityMetadata.unqualify(Product.class), |
253 | | - ignoreCaseTemplate.getIgnoreCaseOperator(), ignoreCaseTemplate.getIgnoreCaseOperator(), |
254 | | - ignoreCaseTemplate.getIgnoreCaseOperator()) // |
| 253 | + DefaultJpaEntityMetadata.unqualify(Product.class), ignoreCaseTemplate.getIgnoreCaseOperator(), |
| 254 | + ignoreCaseTemplate.getIgnoreCaseOperator(), ignoreCaseTemplate.getIgnoreCaseOperator()) // |
255 | 255 | .validateQuery(); |
256 | 256 | } |
257 | 257 |
|
@@ -440,8 +440,8 @@ void likeWithIgnoreCase(JpqlQueryTemplates ignoreCaseTemplate) { |
440 | 440 | .withParameters("%spring%") // |
441 | 441 | .as(QueryCreatorTester::create) // |
442 | 442 | .expectJpql("SELECT p FROM %s p WHERE %s(p.name) LIKE %s(?1) ESCAPE '\\'", |
443 | | - DefaultJpaEntityMetadata.unqualify(Product.class), |
444 | | - ignoreCaseTemplate.getIgnoreCaseOperator(), ignoreCaseTemplate.getIgnoreCaseOperator()) // |
| 443 | + DefaultJpaEntityMetadata.unqualify(Product.class), ignoreCaseTemplate.getIgnoreCaseOperator(), |
| 444 | + ignoreCaseTemplate.getIgnoreCaseOperator()) // |
445 | 445 | .expectPlaceholderValue("?1", "%spring%") // |
446 | 446 | .validateQuery(); |
447 | 447 | } |
@@ -470,8 +470,8 @@ void notLikeWithIgnoreCase(JpqlQueryTemplates ignoreCaseTemplate) { |
470 | 470 | .withParameters("%spring%") // |
471 | 471 | .as(QueryCreatorTester::create) // |
472 | 472 | .expectJpql("SELECT p FROM %s p WHERE %s(p.name) NOT LIKE %s(?1) ESCAPE '\\'", |
473 | | - DefaultJpaEntityMetadata.unqualify(Product.class), |
474 | | - ignoreCaseTemplate.getIgnoreCaseOperator(), ignoreCaseTemplate.getIgnoreCaseOperator()) // |
| 473 | + DefaultJpaEntityMetadata.unqualify(Product.class), ignoreCaseTemplate.getIgnoreCaseOperator(), |
| 474 | + ignoreCaseTemplate.getIgnoreCaseOperator()) // |
475 | 475 | .expectPlaceholderValue("?1", "%spring%") // |
476 | 476 | .validateQuery(); |
477 | 477 | } |
@@ -499,8 +499,8 @@ void startingWithIgnoreCase(JpqlQueryTemplates ignoreCaseTemplate) { |
499 | 499 | .withParameters("spring") // |
500 | 500 | .as(QueryCreatorTester::create) // |
501 | 501 | .expectJpql("SELECT p FROM %s p WHERE %s(p.name) LIKE %s(?1) ESCAPE '\\'", |
502 | | - DefaultJpaEntityMetadata.unqualify(Product.class), |
503 | | - ignoreCaseTemplate.getIgnoreCaseOperator(), ignoreCaseTemplate.getIgnoreCaseOperator()) // |
| 502 | + DefaultJpaEntityMetadata.unqualify(Product.class), ignoreCaseTemplate.getIgnoreCaseOperator(), |
| 503 | + ignoreCaseTemplate.getIgnoreCaseOperator()) // |
504 | 504 | .expectPlaceholderValue("?1", "spring%") // |
505 | 505 | .validateQuery(); |
506 | 506 | } |
@@ -528,8 +528,8 @@ void endingWithIgnoreCase(JpqlQueryTemplates ignoreCaseTemplate) { |
528 | 528 | .withParameters("spring") // |
529 | 529 | .as(QueryCreatorTester::create) // |
530 | 530 | .expectJpql("SELECT p FROM %s p WHERE %s(p.name) LIKE %s(?1) ESCAPE '\\'", |
531 | | - DefaultJpaEntityMetadata.unqualify(Product.class), |
532 | | - ignoreCaseTemplate.getIgnoreCaseOperator(), ignoreCaseTemplate.getIgnoreCaseOperator()) // |
| 531 | + DefaultJpaEntityMetadata.unqualify(Product.class), ignoreCaseTemplate.getIgnoreCaseOperator(), |
| 532 | + ignoreCaseTemplate.getIgnoreCaseOperator()) // |
533 | 533 | .expectPlaceholderValue("?1", "%spring") // |
534 | 534 | .validateQuery(); |
535 | 535 | } |
@@ -620,8 +620,7 @@ void sortBySingleIgnoreCase(JpqlQueryTemplates ignoreCase) { |
620 | 620 | .render(); |
621 | 621 |
|
622 | 622 | assertThat(jpql).isEqualTo("SELECT o FROM %s o ORDER BY %s(o.date) asc", |
623 | | - DefaultJpaEntityMetadata.unqualify(Order.class), |
624 | | - ignoreCase.getIgnoreCaseOperator()); |
| 623 | + DefaultJpaEntityMetadata.unqualify(Order.class), ignoreCase.getIgnoreCaseOperator()); |
625 | 624 | } |
626 | 625 |
|
627 | 626 | @Test // GH-3588 |
@@ -759,8 +758,7 @@ void doesNotCreateJoinForRelationshipEmbeddedId() { |
759 | 758 | .forTree(ReferencingEmbeddedIdExampleEmployee.class, "findByEmployee_EmployeePk_EmployeeId") // |
760 | 759 | .withParameters(1L) // |
761 | 760 | .as(QueryCreatorTester::create) // |
762 | | - .expectJpql( |
763 | | - "SELECT r FROM ReferencingEmbeddedIdExampleEmployee r WHERE r.employee.employeePk.employeeId = ?1") // |
| 761 | + .expectJpql("SELECT r FROM ReferencingEmbeddedIdExampleEmployee r WHERE r.employee.employeePk.employeeId = ?1") // |
764 | 762 | .validateQuery(); |
765 | 763 | } |
766 | 764 |
|
@@ -1137,43 +1135,47 @@ JpaQueryCreator initJpaQueryCreator() { |
1137 | 1135 | } |
1138 | 1136 |
|
1139 | 1137 | @Test // GH-4135 |
1140 | | - void interfaceProjectionWithMultipleJoinsShouldGenerateUniqueAliases() { |
| 1138 | + void interfaceProjectionShouldGenerateUniqueSelectionAliases() { |
1141 | 1139 |
|
1142 | | - queryCreator(ORDER_WITH_RELATIONS) |
1143 | | - .forTree(OrderWithRelations.class, "findProjectionById") |
1144 | | - .returning(OrderSummaryProjection.class) |
1145 | | - .withParameters(1L) |
1146 | | - .as(QueryCreatorTester::create) |
| 1140 | + queryCreator(ORDER_WITH_RELATIONS).forTree(OrderWithRelations.class, "findProjectionById") |
| 1141 | + .returning(OrderSummaryProjection.class) // |
| 1142 | + .withParameters(1L) // |
| 1143 | + .as(QueryCreatorTester::create) // |
1147 | 1144 | .expectJpql( |
1148 | 1145 | "SELECT o.id id, c.id customerId, s.id supplierId, c.name customerName, s.name supplierName FROM %s o LEFT JOIN o.customer c LEFT JOIN o.supplier s WHERE o.id = ?1", |
1149 | 1146 | DefaultJpaEntityMetadata.unqualify(OrderWithRelations.class)) |
1150 | 1147 | .validateQuery(); |
1151 | 1148 | } |
1152 | 1149 |
|
1153 | | - @jakarta.persistence.Entity |
| 1150 | + @Entity |
1154 | 1151 | static class OrderWithRelations { |
1155 | 1152 | @Id Long id; |
1156 | 1153 | @ManyToOne Customer customer; |
1157 | 1154 | @ManyToOne Supplier supplier; |
1158 | 1155 | } |
1159 | 1156 |
|
1160 | | - @jakarta.persistence.Entity |
| 1157 | + @Entity |
1161 | 1158 | static class Customer { |
1162 | 1159 | @Id Long id; |
1163 | 1160 | String name; |
1164 | 1161 | } |
1165 | 1162 |
|
1166 | | - @jakarta.persistence.Entity |
| 1163 | + @Entity |
1167 | 1164 | static class Supplier { |
1168 | 1165 | @Id Long id; |
1169 | 1166 | String name; |
1170 | 1167 | } |
1171 | 1168 |
|
1172 | 1169 | interface OrderSummaryProjection { |
| 1170 | + |
1173 | 1171 | Long getId(); |
1174 | | - Long getCustomerId(); // → customer.id |
1175 | | - Long getSupplierId(); // → supplier.id |
1176 | | - String getCustomerName(); // → customer.name |
1177 | | - String getSupplierName(); // → supplier.name |
| 1172 | + |
| 1173 | + Long getCustomerId(); // customer.id |
| 1174 | + |
| 1175 | + Long getSupplierId(); // supplier.id |
| 1176 | + |
| 1177 | + String getCustomerName(); // customer.name |
| 1178 | + |
| 1179 | + String getSupplierName(); // supplier.name |
1178 | 1180 | } |
1179 | 1181 | } |
0 commit comments