There seems to be a gap in JPA 2.0 or in spring-data-jpa when Entities shall be sorted by Sub-Entities if the Sub-Entities are null.

In this demo application this behavior is shown by two very simple entities:

  • Employee
  • Address

each employee may contain a Address.

In the testcase which fails three Employees are created. Two contain an Address, the third has no Address. Finding all Employees sorted by Address.street causes JPA 2.0 and spring-data-jpa to return only 2 Employees but one would expect to get all 3 Employees.


This behavior is discussed in the spring-data-jpa forum: http://forum.springsource.org/showthread.php?135905-spring-data-jpa-Eclipselink-and-sorting-problems

Running Example

To run the example using Maven in the command line use

mvn test

The logging is configured to show the SQL statements created by Eclipselink.

To run the example in Eclipse ensure to add the spring-instrument jar as java argument like