0
我想通过使用标准API从选定查询的数据库中获取数据。如何从休眠条件api中获取选定的数据?
例如:
select firstname,empid from emp where empid=10 &&
empname='bhanu' || salary=25000;
我该怎么办呢?
我想通过使用标准API从选定查询的数据库中获取数据。如何从休眠条件api中获取选定的数据?
例如:
select firstname,empid from emp where empid=10 &&
empname='bhanu' || salary=25000;
我该怎么办呢?
使用Criteria API而不是纯HQL时有一些设置。
Criteria API文档非常好,如果您有特定问题,我会建议您查看并发回。
如果这更多的是一个设计问题,我会问你选择Criteria over HQL的原因是什么。
是否有特定要求?
使用Criteria查询是这样的:
Criteria criteria = session.createCriteria(Emp.class)
.setProjection(Projections.projectionList()
.add(Projections.property("firstName"))
.add(Projections.property("empId")));
Criterion criterion= Restrictions.and(Restrictions.eq("empId", 10),
Restrictions.eq("empName", "bhanu"));
criteria.add(Restrictions.or(criterion, Restrictions.eq("salary", 25000)));
List result=criteria.list();