0
我也忒以下在級聯保存袋使用Hibernate和Spring MVC
public class Parent {
private Integer id;
private List<Child> detail = ShrinkableLazyList.decorate(
new ArrayList<Child>(),
FactoryUtils.instantiateFactory(Child.class));
與它對應的HBM如下父類:
<class name="Parent" table="parents">
<id name="id">
<generator class="increment"></generator>
</id>
<bag name="detail" cascade="all-delete-orphan">
<key column="parentId" not-null="true" />
<one-to-many class="Child" />
</bag>
</class>
在我的JSP編輯表單我列出這個細節如下:
<c:forEach items="${ parent.detail }" var="child" varStatus="status">
<tr class="detail">
<td>
<input name="detail[${ status.count }].id" type="hidden" value="${ child.id }">
<input name="detail[${ status.count }].account" type="hidden" value="${ child.account.id }"><span>${ child.account }</span>
</td>
</tr>
</c:forEach>
但是,當我嘗試對父對象執行update()
我收到以下內容錯誤:
identifier of an instance of Child was altered from 20 to 19; nested exception is org.hibernate.HibernateException: identifier of an instance of Child was altered from 20 to 19
這是我的DAO代碼
@Override
public void update (Parent parent) {
hibernateTemplate.update(parent);
}
任何想法?謝謝
有沒有問題'status.count'是基於1而不是0基於? –
給那個男人一個餅乾!請發表您的評論作爲答案,所以我可以給你你的獎勵:) –