[jboss-as7-dev] [EE7/JPA 2.1] Question about accessing the CDI BeanManager for a component on AS7 or later...

Scott Marlow smarlow at redhat.com
Wed Aug 22 09:49:23 EDT 2012


I would like to give feedback to the JPA 2.1 EG, on the entity listener 
enhancement to support CDI.  If the deployment archive that contains the 
persistence unit, is a bean archive, the BeanManager needs to be passed 
in as a property when creating the persistence unit service.  The 
persistence provider will use the BeanManager to create instances of the 
entity listener classes, do injection and trigger lifecycle methods.

Currently, the only way to get the CDI BeanManager in AS7, is doing a 
"java:comp/BeanManager" lookup (not helpful during deployment) or via 
the BeanManagerService.  I tried to have the PersistenceUnitService 
depend on the BeanManagerService, but couldn't start the 
PersistenceUnitService  service (got a 
"org.jboss.msc.service.CircularDependencyException: Service jboss-as has 
a circular dependency" http://pastie.org/4565684).

I'll also need to get access to the BeanManager earlier than the install 
phase.  I need to pass the BeanManager as a property to the 
PersistenceProvider.createContainerEntityManagerFactory(PersistenceUnitInfo, 
Map) invocation which might occur early (if class transformers will 
rewrite application classes before they are loaded).

I could avoid having the PU service depend on the BeanManagerService if 
I instead arrange for the PU service to get the BeanManager from the 
deployment unit (if available).  However, if the BeanManagerService is 
stopped, the pu service wouldn't be stopped if we have a direct 
reference to the BeanManager.  So, this (deployment unit) hack sounds 
less than ideal.

Git branch 
https://github.com/scottmarlow/jboss-as/tree/seven_jpa2_1_BeanManager 
integrates with the latest Hibernate master branch (Hibernate needs to 
be built locally) and has the currently broken BeanManager access code 
(gets the CircularDependencyException during deployment).

Scott


More information about the jboss-as7-dev mailing list