|
23 | 23 | import java.util.Collection;
|
24 | 24 | import java.util.Iterator;
|
25 | 25 | import java.util.List;
|
26 |
| -import java.util.Set; |
27 | 26 |
|
28 | 27 | import javax.persistence.criteria.CriteriaBuilder;
|
29 | 28 | import javax.persistence.criteria.CriteriaQuery;
|
@@ -62,10 +61,10 @@ public class JpaQueryCreator extends AbstractQueryCreator<CriteriaQuery<? extend
|
62 | 61 | /**
|
63 | 62 | * Create a new {@link JpaQueryCreator}.
|
64 | 63 | *
|
65 |
| - * @param tree |
66 |
| - * @param domainClass |
67 |
| - * @param accessor |
68 |
| - * @param em |
| 64 | + * @param tree must not be {@literal null}. |
| 65 | + * @param type must not be {@literal null}. |
| 66 | + * @param builder must not be {@literal null}. |
| 67 | + * @param provider must not be {@literal null}. |
69 | 68 | */
|
70 | 69 | public JpaQueryCreator(PartTree tree, ReturnedType type, CriteriaBuilder builder,
|
71 | 70 | ParameterMetadataProvider provider) {
|
@@ -93,7 +92,8 @@ protected CriteriaQuery<? extends Object> createCriteriaQuery(CriteriaBuilder bu
|
93 | 92 |
|
94 | 93 | Class<?> typeToRead = type.getTypeToRead();
|
95 | 94 |
|
96 |
| - return (typeToRead == null || tree.isExistsProjection()) ? builder.createTupleQuery() : builder.createQuery(typeToRead); |
| 95 | + return typeToRead == null || tree.isExistsProjection() ? builder.createTupleQuery() |
| 96 | + : builder.createQuery(typeToRead); |
97 | 97 | }
|
98 | 98 |
|
99 | 99 | /**
|
@@ -168,24 +168,26 @@ protected CriteriaQuery<? extends Object> complete(Predicate predicate, Sort sor
|
168 | 168 | }
|
169 | 169 |
|
170 | 170 | query = query.multiselect(selections);
|
| 171 | + |
171 | 172 | } else if (tree.isExistsProjection()) {
|
172 | 173 |
|
173 | 174 | if (root.getModel().hasSingleIdAttribute()) {
|
174 | 175 |
|
175 | 176 | SingularAttribute<?, ?> id = root.getModel().getId(root.getModel().getIdType().getJavaType());
|
176 | 177 | query = query.multiselect(root.get((SingularAttribute) id).alias(id.getName()));
|
| 178 | + |
177 | 179 | } else {
|
178 | 180 |
|
179 | 181 | List<Selection<?>> selections = new ArrayList<Selection<?>>();
|
180 | 182 |
|
181 |
| - Set<SingularAttribute<?, ?>> idClassAttributes = (Set<SingularAttribute<?, ?>>) root.getModel().getIdClassAttributes(); |
182 |
| - |
183 |
| - for (SingularAttribute<?, ?> attribute : idClassAttributes) { |
| 183 | + for (SingularAttribute<?, ?> attribute : root.getModel().getIdClassAttributes()) { |
184 | 184 | selections.add(root.get((SingularAttribute) attribute).alias(attribute.getName()));
|
185 | 185 | }
|
| 186 | + |
186 | 187 | selections.add(root.get((SingularAttribute) id).alias(id.getName()));
|
187 | 188 | query = query.multiselect(selections);
|
188 | 189 | }
|
| 190 | + |
189 | 191 | } else {
|
190 | 192 | query = query.select((Root) root);
|
191 | 193 | }
|
|
0 commit comments