开发者

Google App Engine / Java - inconsistent ORDER BY

I am using JPA on top of App Engine (I am quite new to both) and I am currently facing a behaviour I do not understand.

Each time I refresh the page, the order of the fetched items changes.

Here is the code snippet:

Set<Cast> results = new HashSet<Cast>();
EntityManager entityManager = entityManagerFactory.createEntityManager();
Query query = entityManager.createQuery(FIND_ALL_SORTED_BY_DESCENDING_BROADCAST_DATE);
@SuppressWarnings("unchecked")
List<Cast> casts = query.getResultList();
for (Cast cast : casts) {
    if (verifySecondaryFields(cast)) {
        results.add(synchronizeTechnicalFields(cast));
    }
}
entityManager.close();
return Collection开发者_JS百科s.unmodifiableSet(results);

where FIND_ALL_SORTED_BY_DESCENDING_BROADCAST_DATE actually is SELECT cast FROM Cast cast ORDER BY cast.broadcastDate DESC.

entityManagerFactory is an autowired member of my repository class.

The thing is the ORDER BY clause seems to be ignored and the results show up randomly. Can you spot what is wrong?


Sets don't preserve order. Lists do. Try List<Cast> = new ArrayList<Cast>(); and carry on from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜