SEVERE:org.hibernate.MappingException:未知的命名查询:

时间:2012-12-10 16:07:43

标签: java spring hibernate

在我的Entity类中,我有以下内容,调用一个返回sys_refcursor

的oracle函数
    @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 {

在DAO我有

@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;
    }

但是当我运行我的应用程序时,我收到以下异常

  

exception命名查询未知:getEmp       SEVERE:org.hibernate.MappingException:未知的命名查询:getEmp           在org.hibernate.internal.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:149)           在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)

如何解决此问题?任何帮助都非常值得赞赏。

1 个答案:

答案 0 :(得分:2)

我已通过在 applicationContext.xml 中添加以下内容来解决此问题。

<property name="annotatedClasses">  
          <list>
           <value>net.test.model.Employees</value>
           </list>  
           </property>