我有一个具有这种关系的类 ContactAddress.java
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "CNTRY_ID")
private Country country;
Country.java 有这些东西
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "CNTRY_ID")
private Integer id;
@Column(name = "NM")
private String name;
@Column(name = "ISO_CD")
private String isoCode;
@Column(name = "SRT_ORDR")
private Integer sortOrder;
@OneToMany(mappedBy="country")
private List<State> states = new ArrayList<State>();
在 ContactAddressAction.java 我调用 save 方法
public String save() throws Exception {
// Add the relationship
contactAddress.setAccount(getAccount());
// Is this an update?
if (index != null) {
getAccount().getContactAddresses().set(index, contactAddress);
} else {
List<ContactAddress> contactAddressList = getAccount().getContactAddresses();
contactAddressList.add(contactAddress);
//getAccount().getContactAddresses().add(contactAddress);
getAccount().setContactAddresses(contactAddressList);
}
return SUCCESS;
}
调用此方法时出现上述异常。联系人地址列表保存在数据库中,但保存后不会立即显示。
JSP代码
c:forEach items="${addresses}" var="address" varStatus="stat">
<s:url id="updateAddressUrl" action="update" namespace="/account/address">
<s:param name="index" value="${stat.index}" />
</s:url>
<s:url id="deleteAddressUrl" action="delete" namespace="/account/address">
<s:param name="index" value="${stat.index}" />
</s:url>
<tr class="address deletable">
<td>${address.type}</td>
<td>${address.primary ? 'Yes' : 'No'}</td>
<td>${address.active ? 'Yes' : 'No'}</td>
<td>${address.companyName}</td>
<td>
<v:address value="${address}"/>
<hr>
<table class="info">
<tr>
<th>Best Contact Time:</th>
<td>${address.bestContactTime}</td>
</tr>
<tr>
<th>Office Hours:</th>
<td>
Monday: <span class="value">${address.officeHourMonday}</span>
Tuesday:<span class="value">${address.officeHourTuesday}</span>
Wednesday:<span class="value">${address.officeHourWednesday}</span>
Thursday:<span class="value">${address.officeHourThursday}</span>
Friday:<span class="value">${address.officeHourFriday}</span>
</td>
</tr>
<tr>
<th>Lunch Time:</th>
<td>${address.officeLunchTime}</td>
</tr>
</table>
</td>
<td class="actions">
<a href="${updateAddressUrl}" class="popup-link button-link"><strong>Edit</strong></a>
<c:if test="${user.primaryAddressManageable}">
<a href="${deleteAddressUrl}" class="deletelink button-link"><strong>Delete</strong></a>
</c:if>
</td>
</tr>
</c:forEach>
此外,如果我调试代码并通过 VARIABLES 查找 List 变量,它工作正常并在保存后显示列表。
我哪里不对?