When I call:
entityManager.flush()
I get the exception mentioned in the title.
I am using Hibernate JPA.
Ensure that you have an active transaction when this statement executes. If you are using JPA use EntityManager.getTransaction().begin(). This is assuming that you are using JPA outside a JTA transaction scope.
EntityManager.getTransaction().begin()