Tutorials
The NetBeans E-commerce Tutorial - Adding Entity Classes and Session Beans
A Java EE container contains three essential components:
- a web (i.e., servlet) container
- an EJB container
- a persistence provider
Persistence unit
A persistence unit refers to a collection of entity classes that exist in an application.
@Entity
The EntityManager maps the entity onto a database.
Entity Manager
In CMEM (Container-Managed Entity Managers) an EnityManager is managed by the container.
CMEM uses the Java JTA transaction API.
@PersistenceContext(unitName="BankService") private EntityManager em;
Calls the container created, EntityManagerFactory (we should have one EntityManagerFactory per Database) to create EntityManager instance and inject this into the local variable.
Whenever a new transaction start a new persistent context is created.
This means that for a stateful session bean each method invocation is a separated transaction. In consequence a new persistence context is created! ==> The entity become detached a need of a merge operation.
persistence.xml
It is used by the persistence provicer (e.g. Hibernate or EclipseLink) to specify configuration settings for the persistence unit.
In Netbeans the "Table Generation Strategy" execute the chosen action each time the project is deployed