2

In my Entity class I have the following, calling a oracle function which returns sys_refcursor

    @Entity
    @javax.persistence.NamedNativeQuery(name = "getEmp", 
    query = "{ ? = call getemployees }", resultClass = Employees.class, hints = {
    @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
    @Table(name = "EMPLOYEES")
    public class Employees {

and in DAO I have

@Inject
    private SessionFactory sessionFactory;

    @Override
    public List<Employees> getEmployees() {

        List query = new ArrayList<Employees>();
         try{
         query = sessionFactory.getCurrentSession()
                .getNamedQuery("getEmp").list();
         }
         catch(Exception e){
             System.out.println("exception "+e.getMessage());
             e.printStackTrace();
         }
        return query;
    }

But when I run my application I am getting the following exception

exception Named query not known: getEmp SEVERE: org.hibernate.MappingException: Named query not known: getEmp at org.hibernate.internal.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:149) at org.hibernate.internal.SessionImpl.getNamedQuery(SessionImpl.java:1257) at net.test.employees.dao.EmployeesDAO.getEmployees(EmployeesDAO.java:34) at net.test.employees.service.EmployeesService.getEmployees(EmployeesService.java:24)

How can I resolve this issue? Any help is highly appreciable.

1 Answer 1

2

I have resolved the issue by adding the following in applicationContext.xml.

<property name="annotatedClasses">  
          <list>
           <value>net.test.model.Employees</value>
           </list>  
           </property>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.