Hello,
I’m trying to make a method inside a bean, that get’s called periodically to clean the DB from the soft-deleted entities older than a day, let’s say.
Collection<MetaClass> metaClasses = metadata.getClasses();
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
CommitContext commitContext = new CommitContext();
commitContext.setJoinTransaction(true);
commitContext.setSoftDeletion(false);
metaClasses.forEach(metaClass -> {
List<Entity<Object>> list = transactionalDataManager.load(metaClass.getJavaClass())
.query(
"select e from " + metaClass.getName() + " e " +
"where e.deleteTs is not null" +
"and e.deleteTs < :date"
)
.parameter("date", calendar.getTime())
.softDeletion(false)
.list();
commitContext.getRemoveInstances().addAll(list);
});
EntitySet entitySet = dataManager.commit(commitContext);
log.info("Successfully deleted " + entitySet.size() + " entities .");
This is the method that does all the magic, but at the dataManager.commit(commitContext)
line, I get the following exception:
remove-issue.txt (10.8 KB)
Why can this happen?
Thank you,
Alex