Hibernate: - 找不到本机查询异常

时间:2013-10-05 17:36:18

标签: java spring hibernate

我在我的项目中使用Hibernate4和Spring3 + JSF2我定义了一个Native查询,一个是DB表上的Java类,但是当我运行项目时,我得到了异常。

SEVERE: org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: findAllloceValue; nested exception is org.hibernate.MappingException: Named query not known: findAllloceValue
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:690)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:979)
    at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:971)
    at com.kuber.data.db.WCompanyDataDao.fetchAnnouncementType(WCompanyDataDao.java:88)
    at com.kuber.service.dao.CompanyDataService.getAnnouncementType(CompanyDataService.java:65)
    at com.kuber.web.view.AnnouncementBean.fetchAnnouncementType(AnnouncementBean.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:795)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1260)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.kuber.web.server.KuberFilter.doFilter(KuberFilter.java:54)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:611)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.MappingException: Named query not known: findAllloceValue
    at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:93)
    at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1407)
    at org.springframework.orm.hibernate3.HibernateTemplate$33.doInHibernate(HibernateTemplate.java:981)
    at org.springframework.orm.hibernate3.HibernateTemplate$33.doInHibernate(HibernateTemplate.java:979)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    ... 47 more

Oct 5, 2013 10:52:41 PM com.sun.faces.context.AjaxExceptionHandlerImpl log
SEVERE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=searchBtn, Message=org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: findAllloceValue; nested exception is org.hibernate.MappingException: Named query not known: findAllloceValue
Oct 5, 2013 10:52:41 PM com.sun.faces.context.AjaxExceptionHandlerImpl log
SEVERE: org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: findAllloceValue; nested exception is org.hibernate.MappingException: Named query not known: findAllloceValue
javax.faces.event.AbortProcessingException: org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: findAllloceValue; nested exception is org.hibernate.MappingException: Named query not known: findAllloceValue
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:795)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1260)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.kuber.web.server.KuberFilter.doFilter(KuberFilter.java:54)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:611)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: findAllloceValue; nested exception is org.hibernate.MappingException: Named query not known: findAllloceValue
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:690)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:979)
    at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:971)
    at com.kuber.data.db.WCompanyDataDao.fetchAnnouncementType(WCompanyDataDao.java:88)
    at com.kuber.service.dao.CompanyDataService.getAnnouncementType(CompanyDataService.java:65)
    at com.kuber.web.view.AnnouncementBean.fetchAnnouncementType(AnnouncementBean.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
    ... 34 more
Caused by: org.hibernate.MappingException: Named query not known: findAllloceValue
    at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:93)
    at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1407)
    at org.springframework.orm.hibernate3.HibernateTemplate$33.doInHibernate(HibernateTemplate.java:981)
    at org.springframework.orm.hibernate3.HibernateTemplate$33.doInHibernate(HibernateTemplate.java:979)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    ... 47 more

任何人都可以告诉我什么时候我做错了我的表java类是

package com.kuber.data.orm.user;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.ColumnResult;
import javax.persistence.Entity;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.NamedNativeQueries;
import org.hibernate.annotations.NamedNativeQuery;

@NamedNativeQueries({
      @NamedNativeQuery(
              name = "findAllloceValue",
              query = "select distinct as loce_value from lo_config_expression where loce_context='Announcement'",          
              resultSetMapping=  "netConfigMapping") ,
    })

    @SqlResultSetMappings( {
        @SqlResultSetMapping(
                name="netConfigMapping", columns = { 
                @ColumnResult(name = "loce_value"),
            })      
    })

@Entity
@Table(name = "lo_config_expression")
public class LoConfigExpression implements java.io.Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
     private String loceContext;
     private String loceExpression;
     private String loceValue;
     private Date createdTm;
     private Date lastModTm;
    public  LoConfigExpression()
    {

    }

    public  LoConfigExpression(String loceContext,String loceExpression,String loceValue,Date createdTm, Date lastModTm)
    {
        this.loceContext=loceContext;
        this.loceExpression=loceExpression;
        this.loceValue=loceValue;
        this.createdTm=createdTm;
        this.lastModTm=lastModTm;
    }
    @Column(name = "loce_context")
    public String getLoceContext() {
        return loceContext;
    }

    public void setLoceContext(String loceContext) {
        this.loceContext = loceContext;
    }
    @Column(name = "loce_value", length = 256)
    public String getLoceValue() {
        return loceValue;
    }

    public void setLoceValue(String loceValue) {
        this.loceValue = loceValue;
    }
    @Column(name = "loce_expression", length = 256)
    public String getLoceExpression() {
        return loceExpression;
    }

    public void setLoceExpression(String loceExpression) {
        this.loceExpression = loceExpression;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_tm")
    public Date getCreatedTm() {
        return createdTm;
    }

    public void setCreatedTm(Date createdTm) {
        this.createdTm = createdTm;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_mod_tm")
    public Date getLastModTm() {
        return lastModTm;
    }

    public void setLastModTm(Date lastModTm) {
        this.lastModTm = lastModTm;
    }
}

2 个答案:

答案 0 :(得分:0)

你应该导入这些,用于本机查询;

import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;

答案 1 :(得分:0)

你不应该在原生查询中使用普通的SQL吗?

您尝试执行的查询不是SQL,而是HQL。尝试将其重写为普通的SQL。