Java8在我的JPA EclipseLink 2.5.2环境中继续做一些奇怪的事情.我不得不删除问题/sf/ask/1876432841/ 昨天,因为在这种情况下的排序受到奇怪的JPA行为的影响 - 我通过强迫在进行最终排序之前的第一个排序步骤.
仍然在Java 8中使用JPA Eclipselink 2.5.2,以下代码有时不会在我的环境中排序(Linux,MacOSX,两者都使用build 1.8.0_25-b17).它在JDK 1.7环境中按预期工作.
public List<Document> getDocumentsByModificationDate() {
List<Document> docs=this.getDocuments();
LOGGER.log(Level.INFO,"sorting "+docs.size()+" by modification date");
Comparator<Document> comparator=new ByModificationComparator();
Collections.sort(docs,comparator);
return docs;
}
Run Code Online (Sandbox Code Playgroud)
从JUnit测试调用时,上述函数正常工作.在生产环境中进行debbuging时,我会得到一个日志条目:
INFORMATION: sorting 34 by modification date
Run Code Online (Sandbox Code Playgroud)
但是在TimSort中,nRemaining <2的返回语句被命中 - 因此不会发生排序.JPA提供的IndirectList(请参阅jpa返回的集合?)被认为是空的.
static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c,
T[] work, int workBase, int workLen) {
assert c != null && a != null && lo >= 0 && lo <= hi …Run Code Online (Sandbox Code Playgroud)