Problem with User-Managed Transaction and Flush using JTA and Arquillian

0

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();

So far so good! But the object deleted one line above in the test comes in the 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() ?

    
asked by anonymous 08.02.2018 / 18:19

1 answer

0

Do this:

@Test
public void delete()  {


    class1DAO.remove(1);//deleta


    assertNull( class1DAO.find(Class1.class, 1) );// se null ok.

}//
    
08.02.2018 / 20:20