2012-03-19 1 views
0

다음과 같은 양방향 관계가 있습니다. 코스에 여러 개의 지정이있을 수 있습니다. 나는 다음과 같은 시도 할 때인쇄를 시도하는 동안 널 포인터 예외 Eclipselink JPA + Spring 3을 사용하여 부모 - 자식 부모 관계

나는 널 (null) 포인터 예외를 얻고있다 :

I가 다음 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> 

의 방법 및 요청이에서가는 곳이다 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(); 
    } 
} 

나는 JSP 페이지에서 제대로 코스 이름을 볼 수 있어요하지만,

Course Name: ${assignment.course.name} 

나는이 실행하려고 할 때 난 아직도 널 (null) 포인터 예외를 얻을 :

assignment.getCourse().getName() 

을 Spring과 EclipseLink JPA에 익숙하지 않습니다. 도와주세요.

+0

코스가 포스트에서 돌아오고 있는지 확인 했습니까? 나는 당신이 jsp에서 코스 명을 priting하고 있다는 것을 이해합니다. 그것은 응답 동안이지만 제출할 때 서버 디버그 모드에서 과제 내에서 코스를 볼 수 있었던 것입니다. 내 생각 엔 당신이 매핑 개체 (경로 개체에 대한 경로 바인딩을 의미)가 없기 때문에 null로 돌아 오는 것이므로 널 포인터 예외가 발생합니다. 디버그 모드에서이를 확인하고, 예외가 발생하는 줄에 중단 점을 유지하고 코스 객체가 있는지 여부와 관계없이 할당의 인스턴스를 확인합니다. – raddykrish

+0

안녕하세요, 언급 된대로 매핑을 수행하는 방법을 알려주십시오. "내 생각에 매핑이 없습니다 (코스 객체에 대한 경로 바인딩 임)" – user1044209

+0

내가 언급 한 바를 수행했습니다. 코스 객체가 널 값 – user1044209

답변

0

코스가 null 인 것 같습니다. 관계의 양면을 유지하고 있는지 확인하십시오.

+1

아니요, JSP 페이지에서 코스 이름을 볼 수 있기 때문에 코스가 null이 아닙니다. – user1044209