I am using Hibernate 4.0
I have method in my DAO class like the following where method return Entity class Employees
.
I am calling an Oracle function which returns sys_refcursor
. How can I return entityManager.createNamedQuery
in my below method?
Any help is highly appreciated.
@Override
public Employees getEmployeeRecords(String employeeNumber) {
<??> = entityManager.createNamedQuery("myfunction");
return <??>;
}
Query
asQuery query = entityManager.createNamedQuery("getFunc"); query.getResultList();
How can I cast this toEmployees
? Because my method return type is ofEmployees
– Jåcob Feb 17 '13 at 18:02NamedNativeQuery
on yourEmployee
entity, specify value of attributeresultClass = Employee.class
, then when you callquery.getResultList()
, it will return aList<Employee>
just likeNamedQuery
. Though you have to explicitly cast it. – Genzer Feb 17 '13 at 18:09resultClass = Employees.class
. So now can I cast asEmployees e = (Employees) query.getSingleResult();
? – Jåcob Feb 17 '13 at 18:19Employee
entity. – Genzer Feb 17 '13 at 18:24