Annotation Interface PersistenceContext
@Repeatable(PersistenceContexts.class)
@Target({TYPE,METHOD,FIELD})
@Retention(RUNTIME)
public @interface PersistenceContext
Expresses a dependency on a container-managed
When the annotation occurs on a managed bean class, it assigns a
name to the
EntityManager
and its associated persistence context. When this annotation occurs
on a method or field of a managed bean, it declares an injection point
of type EntityManager.
@PersistenceContext EntityManager manager;
EntityManager in the environment referencing
context java:comp/env of the containing module.
@PersistenceContext(name = "LibraryManager")
class Bean
...
EntityManagerFactory =
new InitialContext()
.lookup("java:comp/env/LibraryManager");
...
- Since:
- 1.0
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescription(Optional) The name at which theEntityManageris accessed in the environment referencing context.(Optional) Properties for the container or persistence provider.(Optional) Specifies whether the persistence context is always automatically synchronized with the current transaction or whether the persistence context must be explicitly joined to the current transaction by means of theEntityManager.joinTransaction()method.(Optional) Specifies whether a transaction-scoped or extended persistence context is required.(Optional) The name of the persistence unit as defined in thepersistence.xmlfile.
-
Element Details
-
name
String name(Optional) The name at which theEntityManageris accessed in the environment referencing context. If the specified name does not begin withjava:, then the prefixjava:comp/envis assumed. This member is not usually specified when@PersistenceUnitannotates an injection point.- Default:
""
-
unitName
String unitName(Optional) The name of the persistence unit as defined in thepersistence.xmlfile. This member is optional if there is only one persistence unit defined by the containing module.- Default:
""
-
type
(Optional) Specifies whether a transaction-scoped or extended persistence context is required.- Default:
TRANSACTION
-
synchronization
SynchronizationType synchronization(Optional) Specifies whether the persistence context is always automatically synchronized with the current transaction or whether the persistence context must be explicitly joined to the current transaction by means of theEntityManager.joinTransaction()method.- Since:
- 2.1
- Default:
SYNCHRONIZED
-
properties
PersistenceProperty[] properties(Optional) Properties for the container or persistence provider. Vendor-specific properties may be included in this set of properties. Properties that are not recognized by a vendor are ignored.- Default:
{}
-