Annotation Interface PersistenceUnit
@Repeatable(PersistenceUnits.class)
@Target({TYPE,METHOD,FIELD})
@Retention(RUNTIME)
public @interface PersistenceUnit
Expresses a dependency on an
When the annotation occurs on a managed bean class, it assigns
a name to the
EntityManagerFactory and
its associated persistence unit. When this annotation occurs
on a method or field of a managed bean, it declares an
injection point of type EntityManagerFactory.
@PersistenceUnit EntityManagerFactory factory;
EntityManagerFactory in the environment
referencing context java:comp/env of the containing
module.
@PersistenceUnit(name = "Library")
class Bean
...
EntityManagerFactory factory =
new InitialContext()
.lookup("java:comp/env/Library");
...
- Since:
- 1.0
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescription(Optional) The name at which theEntityManagerFactoryis accessed in the environment referencing context.(Optional) The name of the persistence unit as defined in thepersistence.xmlfile.
-
Element Details
-
name
String name(Optional) The name at which theEntityManagerFactoryis 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:
""
-