In our Java project, we use ORM with hibernate and spring. I had problems deleting persistent objects. For example, this sample method retrieves objects using identifiers and then deletes them:
@Transactional
public void remove(List<Long> ids) {
SearchTemplate template = new SearchTemplate();
template.addParameter("milestoneId",ids);
List <InvoiceQueue> items = this.findByCriteria(template);
...
this.delete(items);
}
The method executes Ok without any exceptions, but does not actually delete items from the database.
Adding the following annotation to the method definition @Transactional(propagation = Propagation.REQUIRES_NEW)solves the problem.
Can someone explain why it does not work with the default distribution type PROPAGATION_REQUIRED.
Thanks in advance.
Environmental Information:
hibernate.version 3.5.5-Final, spring.version 3.0.5.RELEASE
source
share