Spring MVC / Hibernate - NullValueInNestedPathException,无效属性,嵌套属性的值是否为空?

时间:2013-08-08 02:43:26

标签: hibernate spring-mvc

我们目前正在Spring MVC中增强已存在的 Web应用程序(我只是在学习框架)。我尝试将另一个属性添加到正被推入数据库的对象中(我也添加了相应的列),但我不断收到NullValueInNestedPathException错误。

我已经尝试了Google,建议如下:

1)明确声明新属性的构造函数(尝试过,但没有解决) 2)确保你实例化新对象(试过,没有解决)
3)仔细检查财产的getter / setters(他们没关系,不是错误)
4)创建serialVersionUID(nah!)
5)使用调试功能(我做了,我发现属性 null)

请帮忙! T.T以下是代码:

新物业的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;
    }
    ...
}

这是hibernate映射:

<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)

Hi 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如果本帖中缺少某些代码/部分代码,请通知我,以便我发布。

1 个答案:

答案 0 :(得分:0)

我发现了什么问题:似乎我将新属性的列的默认值设置为null!我希望得到同样错误的其他人尝试解决这个问题。 -__-!感谢drurenia感兴趣! :d