我正在考虑将旧的DAO层中的Hibernate标准移植到JPA标准或QueryDSL标准。
由于我从未使用过这两种中的任何一种,我想知道应该使用哪种API ...
这是Hibernate标准:
public Page<ElearningSubscription> findWithPatternLike(String searchPattern, int pageNumber, int pageSize) {
Criteria criteria = getSession().createCriteria(getPersistentClass(), "es");
criteria.createAlias(DB_TABLE_USER_ACCOUNT, "u", CriteriaSpecification.INNER_JOIN);
Conjunction conjunction = Restrictions.conjunction();
String pattern = "%" + searchPattern + "%";
Criterion firstname = Restrictions.ilike("u.firstname", pattern);
Criterion lastname = Restrictions.ilike("u.lastname", pattern);
Criterion email = Restrictions.ilike("u.email", pattern);
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(firstname).add(lastname).add(email);
if (searchPattern.contains(" ")) {
String[] pieces = searchPattern.split(" ");
if (pieces[0] != null) {
Criterion firstnameBis = Restrictions.ilike("u.firstname", pieces[0]);
disjunction.add(firstnameBis);
}
if (pieces[1] != null) {
Criterion lastnameBis = Restrictions.ilike("u.lastname", pieces[1]);
disjunction.add(lastnameBis);
}
}
conjunction.add(disjunction);
OrderList orderList = new OrderList().add(Order.asc("u.firstname")).add(Order.asc("u.lastname")).add(Order.asc("u.email")).add(Order.desc("es.subscriptionDate"));
Page<ElearningSubscription> page = getPage(pageNumber, pageSize, criteria, orderList);
return page;
}
感谢任何指导。
亲切的问候,
Stephane Eybert
答案 0 :(得分:0)
JPA 2标准是官方标准,但Querydsl在以下方面具有优势
这个答案是有偏见的,因为我参与了Querydsl的开发。