Problem :
Relation between ManualCheck & ManualCheckDistribution is one to many,
ManualCheckDistribution to ManualCheckDistributionDetail is one to many.
When I tried to invoke delete Child), hibernate is throwing below exception.
Though we are trying to delete entity, error message talks about persisting an entity.
javax.persistence.EntityNotFoundException: deleted entity passed to persist:
[com.adp.payroll.model.payroll.manualcheck.ManualCheckDistribution#]
Guess hibernate will invoke persist of Parent entity after removing child
entity to synchronize its state with database.
Parent entity Set/Collection of child entities has still a reference to
Child entity which was deleted, because we have not refreshed Set/Collection of child
entities in Parent entity.
When Hibernate calls persist on Parent to synchronize we get the above
exception.
Soution : Before you invoke delete(Child), remove the child entity refernce from the
Set/Collection of child entities in Parent entity
Code snippet:
public void deleteManualCheckDistribution(PayrollAgreementId
payrollAgreementId, String payNumber, int distNumber )throws PayrollServiceException {
ManualCheckDistribution checkDist = getManualCheckDistribution(payrollAgreementId,
payNumber, distNumber);
ManualCheck mc = checkDist.getManualCheck();
Set distList = mc.getManualCheckDistributions();
distList.remove(checkDist);
getEm().remove(checkDist);
}
Thanks,
Bathula.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4082414#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...