我有一个连接查询,我想将它作为休眠条件放入我的程序中。
select a.accountName,a.username,b.name from Account as a , User as b
where a.id=b.accountId and b.name like '%abc%' and a.username like '%def%'
我的标准是这样的:
Criteria userCriteria = session.createCriteria(User.class);
DetachedCriteria accountCriteria = DetachedCriteria.forClass(Account.class);
accountCriteria .add(Restrictions.like("name", "%" + def+ "%"));
accountCriteria.setProjection(Projections.property("id"));
userCriteria.add(Property.forName("accountId").in(accountCriteria));
userCriteria.add(Restrictions.eq("username", "%" + abc+ "%"));
List tmpList = userCriteria.setProjection(Projections.rowCount()).list();
userCriteria.setMaxResults(pageSize);
result = userCriteria.list();
列表 tmpList 显示为空。我可以列出之前的所有数据:
List tmpList = userCriteria.setProjection(Projections.rowCount()).list();
这条线有什么问题?