即使值在表中可用,Hibernate也会返回空列表

时间:2016-06-22 15:34:10

标签: java sql hibernate

我看了这里发布的各种解决方案,但没有任何效果。

控制器

List<Company> empIds = empDao.findempbyId(Id,branch);
logger.info("Emp List:"+empIds );

Dao Layer

private static final String FIND_EMPLOYEES = "select EMP_ID from myschema.emp where id = :Id and branch = :branch";

@SuppressWarnings("unchecked")
@Transactional
public List<Company> findempbyId(String Id, String branch) {        
    return getSession().createSQLQuery(FIND_EMPLOYEES)
            .setParameter("Id", Id)
            .setParameter("branch", branch)
            .list();
}

输出

Emplist : []

1 个答案:

答案 0 :(得分:0)

试试这个

Query query = session.createSQLQuery(
    "select EMP_ID from myschema.emp where EMP_ID.id = :Id ;)
    .addEntity(Employee.class)
    .setParameter("Id", "72");
    .setParameter("branch", "branch");
    List result = query.list();