-->
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.  [ 4 posts ] 
Author Message
 Post subject: Cascade all-delete-orphan doesn't work with Web Services
PostPosted: Tue May 12, 2009 6:06 am 
Newbie

Joined: Wed May 06, 2009 6:43 am
Posts: 5
Hi all,
I have a very strange Hibernate problem with Cascade="all-delete-orphan". As premise, I expose some DAO functionalities as Web Service with Apache CXF and Spring. In particular I have this service interface:
Code:
@WebService
public class RawDataServiceImpl implements RawDataService {
   
        private RawDataDao rawDataDao;    
 
        @Override   
   public void updateRawData(RawData rawData) {
      try {
         rawDataDao.saveRawData(rawData);
      } catch (DaoException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }      
   }
}

public class RawDataDaoHibernateImpl implemenets RawDataDao extends HibernateTemplate {
   
   public void saveRawData(RawData rawData) {
      getHibernateTemplate().saveOrUpdate(rawData);      
   }
}


As database structure, I have one entity parent (RawData) and one entity child (ChangeRequest), mapped as following:

Code:
<hibernate-mapping package="it.ids.plx.model.bean">
<class name="RawData" table="RAWD_RAWDATAS">
  <id column="RAWDATA_ID" name="id">
   <generator class="native"/>
  </id> 
  <property column="DESCRIPTION" generated="never" lazy="false"
   name="description" type="string"/>
  <property column="SUMMARY" generated="never" lazy="false"
  <set name="changeRequests" table="RAWD_CHANGE_REQUESTS" cascade="all-delete-orphan" lazy="false">
        <key column="RAWDATA_ID"/>
        <one-to-many class="it.ids.plx.model.bean.ChangeRequest"/>
  </set>
</class>
</hibernate-mapping>
-----------------------------------------------------------------------
<hibernate-mapping package="it.ids.plx.model.bean">
  <class name="ChangeRequest" table="RAWD_CHANGE_REQUESTS">
  <id column="CHANGEREQ_ID" name="id">
   <generator class="native"/>
  </id>
  <property name="comments" column="COMMENTS"></property>
  </class>
</hibernate-mapping>


What it's happening is that, when I execute this code in the WebService client:
Code:
List<RawData> rawDatas = rawDataService.findAllRawDatas();
RawData rawData = rawDatas.get(0);
rawData.getChangeRequests().clear();
rawDataService.updateRawData(rawData);

I find all the instance of ChangeRequest with RAWDATA_ID = null instead of zero elements, only if this call is done via WebService. If I do this call in Unit Test (e.g. AbstractAnnotationAwareTransactionalTests or AbstractDependencyInjectionSpringContextTests) it works fine.

These are the logs of the two identical calls, the first with web service, the second in unit test:
Code:
12/mag/09-09:59:20,690 [DEBUG] SQL:111 - /* update it.ids.plx.model.bean.RawData */ update RAWD_RAWDATAS set DESCRIPTION=?, SUMMARY=?, CREATION_DATE=?, SUBMISSION_DATE=?, EXP_RES_DATE=?, AUTHOR_ID=?, RAWDATA_TYPE_ID=?, RAWDATA_STATUS_ID=?, WORKFLOW_ID=? where RAWDATA_ID=?
12/mag/09-09:59:20,690 [DEBUG] AbstractCollectionPersister:1032 - Deleting collection: [it.ids.plx.model.bean.RawData.changeRequests#66]
12/mag/09-09:59:20,706 [DEBUG] SQL:111 - /* delete one-to-many it.ids.plx.model.bean.RawData.changeRequests */ update RAWD_CHANGE_REQUESTS set RAWDATA_ID=null where RAWDATA_ID=?
12/mag/09-09:59:20,706 [DEBUG] AbstractCollectionPersister:1089 - done deleting collection
12/mag/09-09:59:20,706 [DEBUG] AbstractCollectionPersister:1112 - Inserting collection: [it.ids.plx.model.bean.RawData.changeRequests#66]
12/mag/09-09:59:20,706 [DEBUG] AbstractCollectionPersister:1200 - collection was empty
12/mag/09-09:59:20,753 [DEBUG] SessionImpl:401 - disconnecting session

-------------------
Code:
12/mag/09-10:01:51,313 [DEBUG] SQL:111 - /* update it.ids.plx.model.bean.RawData */ update RAWD_RAWDATAS set DESCRIPTION=?, SUMMARY=?, CREATION_DATE=?, SUBMISSION_DATE=?, EXP_RES_DATE=?, AUTHOR_ID=?, RAWDATA_TYPE_ID=?, RAWDATA_STATUS_ID=?, WORKFLOW_ID=? where RAWDATA_ID=?
12/mag/09-10:01:51,329 [DEBUG] AbstractCollectionPersister:1032 - Deleting collection: [it.ids.plx.model.bean.RawData.changeRequests#66]
12/mag/09-10:01:51,329 [DEBUG] SQL:111 - /* delete one-to-many it.ids.plx.model.bean.RawData.changeRequests */ update RAWD_CHANGE_REQUESTS set RAWDATA_ID=null where RAWDATA_ID=?
12/mag/09-10:01:51,329 [DEBUG] AbstractCollectionPersister:1089 - done deleting collection
[b]12/mag/09-10:01:51,329 [DEBUG] SQL:111 - /* delete it.ids.plx.model.bean.ChangeRequest */ delete from RAWD_CHANGE_REQUESTS where CHANGEREQ_ID=?[/b]
[b]12/mag/09-10:01:51,329 [DEBUG] SQL:111 - /* delete it.ids.plx.model.bean.ChangeRequest */ delete from RAWD_CHANGE_REQUESTS where CHANGEREQ_ID=?[/b]


As you can see, in the second log, the child row is deleted as I want...

I know this problem can be caused from a bunch of factors...
I hope you have any suggestion to help me to solve the problem. Thanks


Top
 Profile  
 
 Post subject: Re: Cascade all-delete-orphan doesn't work with Web Services
PostPosted: Sun Aug 23, 2009 8:54 am 
Newbie

Joined: Sun Aug 23, 2009 8:53 am
Posts: 2
Hi,

did you find a solution? I have the exact same problem.

I did make it work with a work-around, by defining a trigger in the MySQL database that is executed on deletion of a row in the join table and removes the child in the table.

Regards,

Tom


Top
 Profile  
 
 Post subject: Re: Cascade all-delete-orphan doesn't work with Web Services
PostPosted: Tue Sep 01, 2009 10:49 am 
Newbie

Joined: Sun Aug 23, 2009 8:53 am
Posts: 2
TCke83 wrote:
Hi,

did you find a solution? I have the exact same problem.

I did make it work with a work-around, by defining a trigger in the MySQL database that is executed on deletion of a row in the join table and removes the child in the table.

Regards,

Tom


The trigger thing doesn't work. Apparently Spring or Apache CXF deletes all references in the joinTable and re-inserts them, this causes the trigger to be executed for every row and this is not wanted, causes data loss. Does anybody have a solution for this problem?

Regards,

Tom


Top
 Profile  
 
 Post subject: Re: Cascade all-delete-orphan doesn't work with Web Services
PostPosted: Thu Mar 25, 2010 6:59 am 
Newbie

Joined: Wed May 06, 2009 6:43 am
Posts: 5
I'm still fighting with this problem...anyone have found a solution?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.