DATAJPA-974 - Query for tuples now uses joins correctly.

When creating the selections for a derived query using a projection we now explicitly create joins for plural attributes. Looks like Hibernate fails to create a proper query if the path is referred to via root.get(…) and the select clause includes references to other non-plural attributes.
This commit is contained in:
Oliver Gierke
2016-09-28 15:06:27 +02:00
parent bbc72f1265
commit 44d9bf8850
3 changed files with 20 additions and 1 deletions

View File

@@ -156,7 +156,9 @@ public class JpaQueryCreator extends AbstractQueryCreator<CriteriaQuery<? extend
List<Selection<?>> selections = new ArrayList<Selection<?>>();
for (String property : returnedType.getInputProperties()) {
selections.add(root.get(property).alias(property));
PropertyPath path = PropertyPath.from(property, returnedType.getDomainType());
selections.add(toExpressionRecursively(root, path).alias(property));
}
query = query.multiselect(selections);

View File

@@ -226,4 +226,12 @@ public class UserRepositoryFinderTests {
public void translatesNotContainsToNotMemberOf() {
assertThat(userRepository.findByRolesNotContaining(drummer), hasItems(dave, oliver));
}
/**
* @see DATAJPA-974
*/
@Test
public void executesQueryWithProjectionContainingReferenceToPluralAttribute() {
assertThat(userRepository.findRolesAndFirstnameBy(), is(notNullValue()));
}
}

View File

@@ -596,4 +596,13 @@ public interface UserRepository
* @see DATAJPA-858
*/
List<User> findByRolesNameContaining(String name);
List<RolesAndFirstname> findRolesAndFirstnameBy();
static interface RolesAndFirstname {
String getFirstname();
Set<Role> getRoles();
}
}