This is about how the AS-7 JPA layer and related concerns.
Container-managed persistence context
Transaction scope (JPA 7.6.1)
Transaction active invocation
Persistence context is created if none already associated with transaction
Created persistence context ends when transaction ends
An extended persistence context can also be used, which survives when transaction ends.
No transaction invocation
Loaded entities are detached at end of method call.
Extended scope (JPA 7.6.2)
Only supported for stateful session beans.
Entity modifications can be made outside of a transaction and are applied on the next joined transaction (anywhere on the cluster).
Extended persistence context (XPC) is created when stateful bean that depends on a XPC is created.
XPC is closed when dependent session bean(s) are closed (via @remove method).
Inheritance
Stateful beans that create other (local) stateful beans, share the same XPC.
Persistence context propagation (JPA 7.6.3)
A persistence context will be propagated to multiple entity managers (instances) within the same local transaction.
Remote invocations do not propagate the persistence context.
Persistence context propagation requirements for component invocations (JPA 7.6.3.1)
no propagation if component is invoked without a JTA transaction or without the JTA transaction propagating:
Transaction scoped entity manager used within the invoked component, will create a new persistence context.
Extended scoped entity manager used within the invoked component, will use the XPC already bound to the (invoked stateful) bean.
If the entity manager is invoked within a JTA transaction, the persistence context is bound to the JTA transaction.
If a component is invoked and the JTA transaction is propagated into the component:
If (SFSB) component has a XPC and the transaction already has a different persistence context associated with it, an EJBException is thrown by the container.
If a persistence context is bound to the JTA transaction, it is propagated into any entity managers used in the invocation.
Container requirements review
Application-managed persistence context (JPA 7.8.1)
Container needs to inject entity manager factory into jndi for application use.
Must use PersistenceProvider.createContainerEntityManagerFactory method for 3rd party support. Internal APIs are fine for our persistence provider.
Must use EntityManagerFactory.close method to close the entity manager factory prior to shutdown (again for 3rd party support).
Container-managed persistence context (JPA 7.9.1)
For 3rd party support, use EntityManagerFactory.createEntityManager . Consider using for our persistence provider as well.
May pass (PersistenceProperty[]) PersistenceContext.properties to EntityManagerFactory.createEntityManager(Map map) .
Container EM wrapper could implement some EntityManager.unwrap(Class<T> cls) calls but should default to underlying EM for unhandled classes.
Deployment
Extract persistence metadata from persistence.xml
Determine the PersistenceProvider classname for each persistence unit (PU). The default class is currently org.hibernate.ejb.HibernatePersistence.
Invoke the PersistenceProvider.createContainerEntityManagerFactory(PersistenceUnitInfo, Map) to create the EMF that will be used to create all EntityManager's for the PU. The properties read from the PU are passed as the second parameter.
Also pass the “javax.persistence.validation.factory ” property if validation mode is not set to NONE. The validator factory value appears to be org.hibernate.validator.engine.ValidatorFactoryImpl. Consult ValidatorFactoryProvider which is currently used to bootstrap the validator factory in AS6.
The PU classes shouldn't be loaded until after the EMF is created.
The EntityManagerFactory is closed at undeploy time, which also closes all EntityManager's opened by each factory.
Switchboard changes for PU + PC???
Clustering
Determine impact on http://community.jboss.org/wiki/OptimizingentityandXPCreplication which may need to be tweaked for clustering other persistence providers. Judging by the jira status, this optimization is not in place yet (although the Hibernate persistence provider jira HHH-2762 is done).
Determine impact on http://community.jboss.org/wiki/DevEJB3NewSFSBCache (consider support for other persistence providers).
Weld integration (JpaInjectionServices implementation is wired in at boot time)