简体   繁体   English

尝试使用Eclipselink JPA + Spring 3打印Parent-Child Parent关系时出现Null Pointer异常

[英]Null Pointer Exception while trying to print Parent - Child Parent relationship using Eclipselink JPA + Spring 3

I have the following bidirectional relationship : A Course can have several assignments. 我具有以下双向关系:一门课程可以有多个作业。

I am getting a Null Pointer exception when I try the following: 当我尝试以下操作时,出现Null Pointer异常:

I have the following methods in CourseController.java 我在CourseController.java中具有以下方法

@RequestMapping(value="view/{id}/assignment/create")
public ModelAndView createAssignment(@PathVariable("id") String id) throws Exception {

    ModelAndView modelAndView = new ModelAndView("course/assignment/create");
    Assignment assignment = new Assignment();
    assignment.setCourse(this.courseManager.getCourse(id));
    //System.out.println(assignment.getCourse().getName()); This prints the course name correctly
    modelAndView.addObject("assignment", assignment);
    return modelAndView;
}

This is the jsp:
<form:form action="/cbass/assignment/check" method="POST" commandName="assignment">

<form:errors path="*" cssClass="errorblock" element="div"/>
Course Name: ${assignment.course.name}
<table>
    <tr>
        <td>Name : </td>
        <td><form:input path="name" /></td>
        <td><form:errors path="name" cssClass="error" /></td>
    </tr>

    <tr>
    <td colspan="3"><input type="submit" /></td>
    </tr>
</table>

ANd this is where the request goes from the JSP. 这是来自JSP的请求。

@RequestMapping(value = "check", method = RequestMethod.POST)
public String processSubmit(
    @ModelAttribute("assignment") Assignment assignment,
    BindingResult result, SessionStatus status) {

    assignmentValidator.validate(assignment, result);
    System.out.println(assignment.getCourse().getName());
    if (result.hasErrors()) {
        //if validator failed
        return "course/assignment/create";
    } else {
        status.setComplete();
        //form success
        System.out.println("Hello"+assignment.getCourse().getName());
        this.assignmentManager.create(assignment);
        return "course/assignment/view";//+assignment.getId();
    }
}

Although I am able to see the course name properly in the JSP page, 尽管我可以在JSP页面上正确看到课程名称,

Course Name: ${assignment.course.name}

I still get a Null Pointer Exception when I try to execute this: 尝试执行此操作时,我仍然收到Null Pointer异常:

assignment.getCourse().getName()

I am new to Spring and EclipseLink JPA. 我是Spring和EclipseLink JPA的新手。 Please help. 请帮忙。

Seems like your course is null. 好像您的课程为空。 Ensure you are maintaining both sides of the relationship. 确保您维护关系的双方。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 春天在OneToMany JPA Relationship中使用子数据获取父数据 - Fetching parent data using Child Data in OneToMany JPA Relationship in spring Spring JPA如何在子项在多对多关系中持久化时持久化父级 - Spring JPA how to persist parent when the child is persisted in ManyToMany relationship 使用JPA(TreeView)在同一个表中无限的分层子父关系 - Unlimited Hierarchical child parent relationship in the same table using JPA (TreeView) JUNIT-在Spring Data JPA中调用findAll时,空指针异常 - JUNIT - Null pointer Exception while calling findAll in spring Data JPA 使用 spring boot 和 spring 数据 JPA 的 CriteriaQuery 中的空指针异常 - Null pointer exception in CriteriaQuery using spring boot and spring data JPA 尝试使用Jersey 2.7和Spring 3加载Spring应用程序上下文时获取空指针异常 - Getting null pointer exception while trying to load spring application context using jersey 2.7 and spring 3 我可以通过使用Spring Data Jpa一对多单向关系来检索包含父实体ID的子实体 - can i retrieve child entity containing parent entity id by using Spring Data Jpa one-to-many unidirectional relationship 谁应该是 spring JPA 关系中的父级 - Who should be parent in spring JPA relationship @ManyToMany无法使用Spring / JPA / REST从子级到父级工作 - @ManyToMany is not working from Child-to-Parent using Spring/JPA/REST Null 点异常集 spring JPA 关系 - Null point exception on set spring JPA relationship
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM