A custom JPA mapper class has a method:
removeUser()
1. execute 'DELETE' HQL query to remove user
2. call getEntityManager().flush();
3. call getEntityManager().clear();
If I understand clear() correctly, it will remove from context all persistent entities. -source
However, I also read here,
you should define clear architecture- and design guidelines about where a
clear() can be called.
What are clear guidelines on when to call clear()?
The articles explains it. Clearing the entity manager empties its associated cache, forcing new database queries to be executed later in the transaction. It’s almost never necessary to clear the entity manager when using a transaction-bound entity manager. I see two reasons to clear: