Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: Hibernate 3.0.5
Mapping documents:
Code:
<class name="vo.booking.Orders" table="orders">
<id name="ordersId" column="ordersId" type="string" length="14">
<generator class="assigned"/>
</id>
<set name="ordersDetails" table="ordersdetail" cascade="all-delete-orphan" inverse="true" lazy="true">
<key>
<column name="ordersId"/>
</key>
<one-to-many class="vo.booking.OrdersDetail"/>
</set>
</orders>
Under Spring MVC, I update a orders instance after loading it with its ordersDetails in a SimpleFormController, exception raised
Code:
...
protected Object formBackingObject(HttpServletRequest request) throws Exception {
String ordersId = request.getParameter("ordersId");
if (!StringUtils.hasText(ordersId)) {
return new OrdersForm();
} else {
Orders orders = getOrdersService().getOrders(ordersId);
getOrdersService().getOrdersDetails(orders);
return new OrdersForm(orders);
}
}
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
OrdersForm ordersForm = (OrdersForm) command;
getOrdersService().updateOrders(ordersForm.getOrders());
response.sendRedirect(request.getContextPath() + "/orders/ordersMenu.htm");
return null;
}
...
public void updateOrders(Orders orders) throws DataAccessException {
/*
getHibernateTemplate().merge(orders); //org.hibernate.AssertionFailure: entity was not detached
or
getHibernateTemplate().saveOrUpdate(orders); //org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session
*/
}
I believe the exception is due to the many relations when hibernate tried to save the persisted ordersDetail. As it works fine when I do not load the relations.
Changing the cascade settings or not loading the relations are both infeasible for my case.
Are there any solutions for it?
Name and version of the database you are using: Mysql