-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: all-delete-orphan relations failed on update
PostPosted: Sat Feb 11, 2006 1:56 am 
Newbie

Joined: Mon Jul 12, 2004 2:52 am
Posts: 17
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 4:48 am 
Newbie

Joined: Mon Dec 05, 2005 10:25 am
Posts: 16
I don't know :-(
But try rewrite methods equals and hashCode on the pojo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 6:28 am 
Newbie

Joined: Mon Jul 12, 2004 2:52 am
Posts: 17
i implemented equals & hashcode for both the parent and child entities

still not working ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.