2016-08-24 1 views
0

Employee와 City라는 두 개의 테이블이 있습니다 .Employee 테이블에는 City (CityID)에 대한 외래 키가 있습니다. 드롭 다운 목록에서 CityID 값을 가져 오려고하는데 jsp 페이지의 반환 된 모델에 항상 CityID에 대한 null 값이 있습니다.JSP 페이지는 forein 키 매개 변수에 null 값을 보냅니다.

직원 엔티티

@Entity 
@Table(name = "Employee", catalog = "DataGathering", schema = "dbo") 
... 
@JoinColumn(name = "CityID", referencedColumnName = "ID") 
@ManyToOne 
private City CityID; 

도시 엔티티

@Id 
@Basic(optional = false) 
@NotNull 
@Column(name = "ID") 
private Integer id; 
@Basic(optional = false) 
@NotNull 
@Size(min = 1, max = 100) 
@Column(name = "CityName") 
private String cityName; 

@OneToMany(mappedBy = "CityID") 
private Collection<Employee> EmployeeCollection1; 

JSP 양식

<td><form:select path="CityID" > 
<form:options items = "${cityList}" itemValue="id"itemLabel="cityName"/> 
</form:select></td> 

컨트롤러

@RequestMapping(value="/new", method = RequestMethod.POST) 
public String 
processRegistration(@ModelAttribute("tblEmployee")TblEmployee employee, 
BindingResult result, 
       Map<String, Object> model) { 

    employeeService.create(employee); 

    return "employee"; 
} 

ERROR :

Cannot insert the value NULL into column 'CityID', table 
'DataGathering.dbo.Employee'; column does not allow nulls. INSERT fails. 

답변

0

는 잘 모르겠습니다 만 한 번 우는 코드

<td><form:select path="CityID" > 
<form:options items = "${cityList}" itemValue="id"itemLabel="cityName"/> 
</form:select></td> 

을 변경,

<td><form:select path="CityID" > 
<c:forEach item="${cityList}" var="cityList"> 
    <options value= "${cityList.id}" itemLabel="cityName">${cityList.cityName}</option> 
</c:forEach> 
</form:select></td> 

그리고 당신은 JSP 페이지에서 값을 받고 있지 않은 경우 다음과 같이 개체의 변화

fetch = FetchType.EAGER 
+0

응답 해 주셔서 감사합니다. 작동하지 않았습니다. 같은 erorr로 잘못 hrows. –

+0

jsp 페이지에 도시 목록이 표시됩니까? –