Java Reference
In-Depth Information
Listing 10.2. ItemManager using an application-managed EntityManager
The code in this listing is straightforward. First, an EntityManagerFactory is injec-
ted . You create an EntityManager using the injected EntityManagerFactory
after the bean is constructed and lose it before the bean is destroyed. This mirrors
what the container does automatically with a container-managed EntityManager .
The EntityManagerFactory annotation is defined as follows:
@Target({TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface PersistenceUnit {
String name() default "";
String unitName() default "";
}
The name and unitName elements serve exactly the same purpose as they do for the
@PersistenceContext annotation. Whereas the name element can be used to point
to the JNDI name of the EntityManagerFactory , the unitName element is used to
specify the name of the underlying persistence unit.
Search WWH ::




Custom Search