2

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

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

谁能告诉我什么时候做错了我的 Tables java Class 是

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

2 回答 2

0

您不应该在本机查询中使用普通 SQL 吗?

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

于 2013-10-05T17:50:55.633 回答
0

You should import these ones,for native queries;

import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
于 2013-10-05T17:45:47.270 回答