hibernate 一些查询操作

查询数据得到List<Long>

List<Organization> organizationList = Lists.newArrayList();
   
CriteriaBuilder criteriaBuilder = entityManager().getCriteriaBuilder();
CriteriaQuery<Organization> query = criteriaBuilder.createQuery(Organization.class);
Root<Organization> root = query.from(Organization.class);

organizationList = entityManager().createQuery(query.select(root).where(criteriaBuilder.equal(root.get("organizationLeaderWorkNumber"), workNumber)))
                        .getResultList();

List<Long> orgList = Lists.newArrayList();
StringBuffer sbSQL = new StringBuffer(520);
sbSQL.append("select pos.org_id from HCM_OUT_POS pos,HCM_OUT_PLU plu ");
sbSQL.append("       where pos.position_id = plu.plans and plu.spernr = '000001' and pos.is_manager = 'X'");
Query querys = entityManager().createNativeQuery(sbSQL.toString());
orgList = (List<Long>)querys.getResultList();
if(orgList!=null && orgList.size()>0){//删除organizationList包含orgList 的元素对象
Iterator<Organization> iter = organizationList.iterator(); 
while(iter.hasNext()){  
Organization organization = iter.next();  
if(orgList.contains(organization.getOrganizationID())){
iter.remove();  
 }  
}  
}



查询返回条数

 Query userCounts = entityManager().createNativeQuery("select count(*) from pmp_user u1 join" +
                " pmp_user u2 on u1.SUPERVISOR_WORK_NUMBER = u2.WORK_NUMBER " +
                "and u1.WORK_NUMBER = :workNumber and u2.id = :userId");
        userCounts.setParameter("workNumber", requestUserWorkNumber);
        userCounts.setParameter("userId", currentUserId);
        try {
            Object singleResult = userCounts.getSingleResult();
            return ((BigDecimal) singleResult).longValue() > 0;
        } catch (Exception e) {
            return false;
        }





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值