I'm doing some tests with JUnit and, to inject dependencies on it with ICD, I adopted Arquillian. But, there is a problem I did not figure out how to solve without using the flush()
method of EntityManager
.
Basically, I need to remove an object and check that it is not in the object list, which I do with the following commands:
class1DAO.remove(1);
assertFalse(class1DAO.getAll().contains(object1FromClass1));
What method: remove(Class1 class1);
of DAO does is give a: entityManager.remove(class1);
That would be enough to delete the object. From what I understood from Hibernate.
The getAll()
method returns a entityManager.createQuery("from Class1 c", Class1.class).getResultList();
getAll()
method list and my test fails. The only way I found to avoid this is to give entityManager.flush();
just below entityManager.remove(class1);
But I was already using Transaction Manager and Dependency Injection Control, precisely, to avoid having to do this at hand. Is there any way to resolve this without explicitly using flush()
?