When using the EntityManager to load data, if any field is lazily loaded beforehand, the SOFT_DELETION property is turned off in the EntityManager, and soft deleted entities are loaded.
// Two students are created, (Student has m-to-1 `group` field), one of them has been soft deleted.
FetchPlan fetchPlan = fetchPlans.builder(Student.class)
.addFetchPlan(FetchPlan.INSTANCE_NAME)
.build();
PlatformTransactionManager transactionManager = storeAwareLocator.getTransactionManager(Stores.MAIN);
TransactionStatus tx = transactionManager.getTransaction(new DefaultTransactionDefinition());
try {
List<Student> studentsBefore = dataManager.load(Student.class)
.all()
.fetchPlan(fetchPlan)
.list();
System.out.println(String.format("student count before: %s", studentsBefore.size())); //1
log.info("student count before: {}", studentsBefore.size());
System.out.println(String.format("soft-deletion before lazy loading = %s",
entityManager.getProperties().get(PersistenceHints.SOFT_DELETION))); //true
Group group = studentsBefore.get(0).getGroup();
System.out.println(String.format("soft-deletion after lazy loading = %s",
entityManager.getProperties().get(PersistenceHints.SOFT_DELETION))); //false
List<Student> studentsAfter = entityManager.createQuery("select e from Student e", Student.class)
.setHint(PersistenceHints.FETCH_PLAN, fetchPlan)
.getResultList();
System.out.println(String.format("student count after: %s", studentsAfter.size())); //2
transactionManager.commit(tx);
} catch (Exception e) {
transactionManager.rollback(tx);
}
Environment
Jmix version: 1.6.2
Bug Description
When using the EntityManager to load data, if any field is lazily loaded beforehand, the SOFT_DELETION property is turned off in the EntityManager, and soft deleted entities are loaded.
QA Notes
Covered by autotest