Persistence thought of the day

The Java Persistence API defines an EntityManager.close method. After this method is called on an entity manager instance, it is still possible to call methods isOpen and getTransaction on that instance.

While it's clear why the former is allowed, the same requirement for the getTransaction method sounds strange at first glance. For the answer, let's look in the spec itself. In the section 3.1.1 EntityManager Interface, the javadoc for the EntityManager.close contains the following text:


If this method is called when the EntityManager is associated
with an active transaction, the persistence context remains
managed until the transaction completes.

This means that by allowing to call this method on a closed entity manager, the spec allows you to check the status and complete the transaction. (Of course this is all about the resource-local entity manager.)

Let me know, if it's still not clear...

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Marina Vatkina

Search

Top Tags
Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
News

No bookmarks in folder

Blogroll
Related Links