java - deleted object would be re-saved by cascade (remove deleted object from associations) - issue with service method invoking -
i have faced strange problem regarding deleting child object association.
here first object order:
@lazycollection(lazycollectionoption.false) @onetomany(mappedby = "order", orphanremoval=true) @cascade({org.hibernate.annotations.cascadetype.all}) private list<exchangetransaction> exchangetransactions = new arraylist<exchangetransaction>();
here second object exchangetransaction:
@manytoone @joincolumn(name = "orderid", insertable = true, updatable = false) private order order;
i want delete order related exchangetransactions.
if perform delete operation through controller, works fine. here code inside controller:
order order = orderservice.getorder(orderid); user user = order.getuser(); user.removeorder(order); orderservice.removeorder(order);
if delete operation performed @scheduled service, i've got error message:
error [org.springframework.scheduling.support.taskutils$loggingerrorhandler] [] pool-3-thread-1 unexpected error occurred in scheduled task. org.springframework.dao.invaliddataaccessapiusageexception: deleted object re-saved cascade (remove deleted object associations): [currencyexchange.model.exchangetransaction#2];
code inside service object:
@override @transactional @scheduled(cron = "*/30 * * * * *") public void deleteinactiveorders() { orderdao.deleteinactiveorders(); }
code inside dao:
@override public void deleteinactiveorders() { list<order> allinactiveorderslist = sessionfactory.getcurrentsession().createquery("from order orderdate <= sysdate-1").list(); if (allinactiveorderslist.size() >=1 ){ (order order: allinactiveorderslist){ user user = order.getuser(); user.removeorder(order); sessionfactory.getcurrentsession().delete(order); } } }
update: not @scheduled issue. when invoke deleteinactiveorders() controller i've got same error.
Comments
Post a Comment