我正在尝试在以下示例中使用Java 8 lambda:
hibernateTemplate.execute(new HibernateCallback<HumanMainInfo>() {
@Override
public HumanMainInfo doInHibernate(Session session) throws HibernateException {
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<HumanMainInfo> query = builder.createQuery(HumanMainInfo.class);
Root<SysUserMainInfo> sysUserRoot = query.from(SysUserMainInfo.class);
Join<SysUserMainInfo, HumanMainInfo> humanJoin = sysUserRoot.join("human", JoinType.INNER);
Predicate idCondition = builder.equal(sysUserRoot.get("id"), userId);
query.where(idCondition).select(humanJoin);
return session.createQuery(query).uniqueResult();
}
});
答案 0 :(得分:1)
hibernateTemplate.execute(session -> {
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<HumanMainInfo> query = builder.createQuery(HumanMainInfo.class);
Root<SysUserMainInfo> sysUserRoot = query.from(SysUserMainInfo.class);
Join<SysUserMainInfo, HumanMainInfo> humanJoin = sysUserRoot.join("human", JoinType.INNER);
Predicate idCondition = builder.equal(sysUserRoot.get("id"), userId);
query.where(idCondition).select(humanJoin);
return session.createQuery(query).uniqueResult();
});