DATAJPA-346 - EclipseLink specific workaround for joins in QueryUtils.

Added fix in QueryUtils to work around an EclipseLinks specialty to add strict joins on a call to root.get(…) even if a later root.join(…, JoinType.LEFT) should trump this.

We needed the first call to examine the metamodel of the path obtained to decide whether to join at all in next steps. We now work around this issue by doing a lot of ugly type checking and casting on the Metamodel directly.

We filed https://bugs.eclipse.org/bugs/show_bug.cgi?id=413892 to maybe let EclipseLink improve at that point.

Original pull request: #30.
This commit is contained in:
Thomas Darimont
2013-07-26 11:31:50 +02:00
committed by Oliver Gierke
parent 6824cc158e
commit fbb88e8c76
3 changed files with 55 additions and 15 deletions

View File

@@ -51,6 +51,16 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi
}
@Override
public void doesNotDropNullValuesOnPagedSpecificationExecution() {
public void doesNotDropNullValuesOnPagedSpecificationExecution() {}
/**
* Works with a workaround in QueryUtils.toExpressionRecursively(…). TODO: remove once EclipseLink bug is fixed.
*
* @see DATAJPA-346
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=413892
*/
@Override
public void shouldGenerateLeftOuterJoinInfindAllWithPaginationAndSortOnNestedPropertyPath() {
super.shouldGenerateLeftOuterJoinInfindAllWithPaginationAndSortOnNestedPropertyPath();
}
}

View File

@@ -74,12 +74,10 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
public class UserRepositoryTests {
@PersistenceContext
EntityManager em;
@PersistenceContext EntityManager em;
// CUT
@Autowired
UserRepository repository;
@Autowired UserRepository repository;
// Test fixture
User firstUser, secondUser, thirdUser, fourthUser;
@@ -1000,6 +998,28 @@ public class UserRepositoryTests {
assertThat(page, hasItem(firstUser));
}
/**
* @see DATAJPA-346
*/
@Test
public void shouldGenerateLeftOuterJoinInfindAllWithPaginationAndSortOnNestedPropertyPath() {
firstUser.setManager(null);
secondUser.setManager(null);
thirdUser.setManager(firstUser); // manager Oliver
fourthUser.setManager(secondUser); // manager Joachim
flushTestUsers();
Page<User> pages = repository.findAll(new PageRequest(0, 4, new Sort(Sort.Direction.ASC, "manager.firstname")));
assertThat(pages.getSize(), is(4));
assertThat(pages.getContent().get(0).getManager(), is(nullValue()));
assertThat(pages.getContent().get(1).getManager(), is(nullValue()));
assertThat(pages.getContent().get(2).getManager().getFirstname(), is("Joachim"));
assertThat(pages.getContent().get(3).getManager().getFirstname(), is("Oliver"));
assertThat(pages.getTotalElements(), is(4L));
}
/**
* @see DATAJPA-292
*/