JPA2条件构建器查询的内容是什么?
Select * from Transaction t1
where t1.version = (
select max(t2.version)
from Transaction t2
where t1.id=t2.id
)
答案 0 :(得分:3)
类似的东西:
CriteriaQuery<Transaction> query = cb.createQuery(Transaction.class);
Root<Transaction> t1 = query.from(Transaction.class);
Subquery<Integer> maxVersion = query.subquery(Integer.class);
Root<Transaction> t2 = maxVersion.from(Transaction.class);
maxVersion.where(cb.eq(t1.get(Transaction_.id), t2.get(Transaction_.id));
maxVersion.select(cb.max(t2.get(Transaction_.version));
query.where(cb.eq(t1.get(Transaction_.version), maxVersion));
query.select(t1);