9.14.3 Notes on the API functions of EntityManager
This section describes the notes on the API functions provided by EntityManager. For details on the EntityManager APIs, see 8.12 javax.persistence package.
-
When EntityManager of transaction scope persistence context is used, the persist, merge, remove, and refresh methods must be executed in the transaction context. If the transaction context does not exist, javax.persistence.TransactionRequiredException is thrown.
-
The find method and getReference method do not require execution in the transaction context. Therefore, if EntityManager of transaction scope persistence context is used, the resulting entity has a detached state. Also, if EntityManager of extended persistence context is used, the resulting entity has a managed state.
-
If the argument of the createQuery method is not a valid JPQL string, the IllegalArgument exception is sent and the execution of the query fails.
-
If the executed native query does not match the specifications for the database to be connected to or if the defined result set is not compatible with the query results, the execution of the query fails and the PersistenceException exception is thrown when the query is executed.
-
If a runtime exception is sent from a method of the EntityManager interface, the current transaction is marked for rollback.
-
The Query object obtained from EntityManager and the EntityTransaction object are enabled while EntityManager is open.