我们目前正在增强Spring MVC 中现有的Web 应用程序(我只是在学习框架)。我尝试将另一个属性添加到正在推送到数据库中的对象(我也添加了相应的列),但我不断收到NullValueInNestedPathException
错误消息。
我已经尝试过谷歌,建议如下:
1) 显式声明新属性的构造函数(已尝试,未解决)
2) 确保实例化新对象(已尝试,未解决)
3) 仔细检查属性的 getter/setter(它们是好的,不是错误)
4)创建一个serialVersionUID(不!)
5)使用调试功能(我做了,我发现该属性为空)
请帮忙!TT 以下是代码:
新物业的VO:
public class ShiftAssignmentLookupVO implements Serializable{
...
public ShiftAssignmentLookupVO(){}
public String getShiftAssignmentStringValue(){
return shiftAssignmentStringValue;
}
public void setShiftAssignmentStringValue(String shiftAssignmentStringValue){
this.shiftAssignmentStringValue = shiftAssignmentStringValue;
}
...
}
包含属性的对象的VO:
public class EmployeeCalendarVO implements Serializable {
...
//the new property:
private ShiftAssignmentLookupVO shiftAssignmentVO = new ShiftAssignmentLookupVO();
public void setShiftAssignmentVO(ShiftAssignmentLookupVO shiftAssignmentVO){
this.shiftAssignmentVO = shiftAssignmentVO;
}
public ShiftAssignmentLookupVO getShiftAssignmentVO(){
return shiftAssignmentVO;
}
...
}
这是休眠映射:
<class name = "EmployeeCalendarVO" table = "EMP_WRK_CDR">
...
<many-to-one name = "shiftAssignmentVO" lazy = "false">
<column name = "ID_ASSIGNMENT" />
</many-to-one>
...
</class>
我尝试访问该属性的jsp:
<spring:bind path = "employeecalendar.empCalList[${ecl.index}].shiftAssignmentVO.shiftAssignmentID">
...
</spring:bind>
最后(哇!)堆栈跟踪:
Aug 8, 2013 10:36:18 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet dtr threw exception
org.springframework.beans.NullValueInNestedPathException: Invalid property 'empCalList[0].shiftAssignmentVO' of bean class [com.safeway.dtr.employee.vo.EmpCalManager]: Value of nested property 'empCalList[0].shiftAssignmentVO' is null
at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:443)
at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:418)
at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:419)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:524)
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:78)
at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:337)
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:119)
at org.springframework.web.servlet.tags.BindTag.doStartTagInternal(BindTag.java:116)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
at org.apache.jsp.WEB_002dINF.jsp.employee.employeecalendar_jsp._jspService(employeecalendar_jsp.java:1184)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:624)
at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:135)
at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:149)
at org.apache.struts.tiles.taglib.InsertTag.doInclude(InsertTag.java:761)
at org.apache.struts.tiles.taglib.InsertTag$InsertHandler.doEndTag(InsertTag.java:893)
at org.apache.struts.tiles.taglib.InsertTag.doEndTag(InsertTag.java:462)
at org.apache.jsp.WEB_002dINF.jsp.defaultLayout_jsp._jspx_meth_tiles_005finsert_005f1(defaultLayout_jsp.java:286)
at org.apache.jsp.WEB_002dINF.jsp.defaultLayout_jsp._jspService(defaultLayout_jsp.java:115)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:145)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:251)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1144)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:880)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:595)
嗨 drurenia,这是根据要求提供的 empCalManager:
public class EmpCalManager {
...
private List<EmployeeCalendarVO> empCalList = LazyList.decorate(new ArrayList<EmployeeCalendarVO>(),FactoryUtils.instantiateFactory(EmployeeCalendarVO.class));
public List<EmployeeCalendarVO> getEmpCalList() {
return empCalList;
}
public void setEmpCalList(List<EmployeeCalendarVO> empCalList) {
this.empCalList = empCalList;
}
...
}
这件作品从桌子上拉下来:
public List<EmployeeCalendarVO> getEmployeeWorkCalendar(int empId, Date from, Date to){
Session session = sessionFactory.getCurrentSession();
session.flush();
Query query = session.createQuery(" from EmployeeCalendarVO as empWrkCdr where " +
"empWrkCdr.employeeId = ? AND empWrkCdr.workDate between ? AND ? order by empWrkCdr.workDate");
query.setInteger(0, empId);
query.setDate(1, from);
query.setDate(2, to);
return query.list();
}
有任何想法吗?建议?感谢任何会提供帮助的人!
*PS 如果这篇文章中缺少某些代码/部分代码,请通知我,以便我发布它们。