HTTP状态500 - javax.el.PropertyNotFoundException:在类型上找不到属性

时间:2013-11-23 00:35:55

标签: java mysql spring hibernate

我正在做this tutorial,我在spring hibernate MySQL项目中收到以下错误消息:

HTTP Status 500 - javax.el.PropertyNotFoundException:  
Property 'id' not found on type net.viralpatel.docmanager.model.Document  

我需要发布哪些其他信息才能让人们知道如何帮助我修复错误,以便我的应用程序运行?

这是Document类:

@Entity
@Table(name="documents")
public class Document {

    @Id
    @GeneratedValue
    @Column(name="id")
    private Integer id;

    @Column(name="name")
    private String name;

    @Column(name="description")
    private String description;

    @Column(name="filename")
    private String filename;

    @Column(name="content")
    @Lob
    private Blob content;

    @Column(name="content_type")
    private String contentType;

    @Column(name="created")
    private Date created;

    //Getter and Setter methods
    public Integer getID(){return id;}
    public Blob getContent(){return content;}
    public String getContentType(){return contentType;}
    public String getDescription(){return description;}
    public String getFileName(){return filename;}
    public String getName(){return name;}
    public Date getCreated(){return created;}

    public void setID(Integer i){id=i;}
    public void setContent(Blob ct){content=ct;}
    public void setContentType(String ctype){contentType=ctype;}
    public void setDescription(String desc){description=desc;}
    public void setFileName(String fn){filename=fn;}
    public void setName(String nm){name=nm;}
    public void setCreated(){created=new java.sql.Date(System.currentTimeMillis());}
}

以下是从第一个SEVERE开始的堆栈轨道部分:

Nov 22, 2013 4:20:17 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4290 ms
Hibernate: select document0_.id as id1_0_, document0_.content as content2_0_, document0_.content_type as content_3_0_, document0_.created as created4_0_, document0_.description as descript5_0_, document0_.filename as filename6_0_, document0_.name as name7_0_ from documents document0_
Nov 22, 2013 4:20:18 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.el.PropertyNotFoundException: Property 'id' not found on type net.viralpatel.docmanager.model.Document  
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
    at javax.el.BeanELResolver.property(BeanELResolver.java:325)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
    at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
    at org.apache.jsp.WEB_002dINF.jsp.documents_jsp._jspx_meth_c_005fforEach_005f0(documents_jsp.java:435)
    at org.apache.jsp.WEB_002dINF.jsp.documents_jsp._jspx_meth_c_005fif_005f0(documents_jsp.java:389)
    at org.apache.jsp.WEB_002dINF.jsp.documents_jsp._jspService(documents_jsp.java:192)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    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:502)
    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:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Nov 22, 2013 4:20:18 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [spring] in context with path [/DocumentManager] threw exception [javax.el.PropertyNotFoundException: Property 'id' not found on type net.viralpatel.docmanager.model.Document] with root cause
    javax.el.PropertyNotFoundException: Property 'id' not found on type net.viralpatel.docmanager.model.Document
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
    at javax.el.BeanELResolver.property(BeanELResolver.java:325)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
    at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
    at org.apache.jsp.WEB_002dINF.jsp.documents_jsp._jspx_meth_c_005fforEach_005f0(documents_jsp.java:435)
    at org.apache.jsp.WEB_002dINF.jsp.documents_jsp._jspx_meth_c_005fif_005f0(documents_jsp.java:389)
    at org.apache.jsp.WEB_002dINF.jsp.documents_jsp._jspService(documents_jsp.java:192)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    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:502)
    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:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

这是创建基础MySQL表的数据定义语言:

CREATE DATABASE `docdb`;
USE `docdb`;

CREATE TABLE `documents` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `description` text NOT NULL,
  `filename` varchar(200) NOT NULL,
  `content` mediumblob NOT NULL, /* for ORACLE enter BLOB*/
  `content_type` varchar(255) NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
);

2 个答案:

答案 0 :(得分:1)

我认为id访问器与bean命名约定不匹配,这就是抛出异常的原因。它们应该如下:

public Integer getId() { return id; }

public void setId(Integer i){ id= i; }

答案 1 :(得分:1)

没有名为id的属性。但是,有一个名为iD的属性。

这是一个区分大小写的问题。

通过在对象上使用反射查找来推断属性名称。

@Entity
@Table(name="documents")
public class Document {

    @Id
    @GeneratedValue
    @Column(name="id")
    private Integer id;

    //Getter and Setter methods
    public Integer getID(){return id;}
    ...

    public void setID(Integer i){id=i;}
    ...
}

http://docstore.mik.ua/orelly/java-ent/jnut/ch06_02.htm