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:
@@ -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);
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user