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.
If you are running the application inside a container with JTA support you can also use JTA UserTransaction to manage transactions.