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