[jboss-user] [JBoss/Spring Integration] - Chicken-Egg with PersistenceAnnotationBeanPostProcessor

Saish do-not-reply at jboss.com
Tue Jul 15 13:53:58 EDT 2008


I have been trying to set-up a PersistenceAnnotationBeanPostProcessor using "vanilla" JNDI lookups to leverage all of the configuration we already have in JBoss (e.g., persistence.xml, JPA entites, etc.)  I have run into what seems to be a chicken-egg issue with the ordering of the Spring-JBoss Deployer.

If I use something like the following in an application context loaded by the deployer:


  |     <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" lazy-init="true">
  |         <property name="persistenceUnits">
  |             <map>
  |                 <entry key="foo" value="java:/persistence-units/foo"/>
  |             </map>
  |         </property>
  |     </bean>
  | 

And specifically instruct JBoss to expose its EJB3 EntityManagerFactory via the following in persistence.xml:


  | 	<persistence-unit name="foo">
  | 		<provider>org.hibernate.ejb.HibernatePersistence</provider>
  | 		<jta-data-source>java:/Foo</jta-data-source>
  | 		<properties>
  | 			<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
  | 			<property name="jboss.entity.manager.factory.jndi.name" value="java:/persistence-units/foo"/>
  | 		</properties>
  | 	</persistence-unit>
  | 

I get a javax.naming.NamingException (unable to find 'java:/persistence-units/foo").  Looking at the logs, I noticed that the Spring-JBoss Deployer deploys *before* the EJB-managed JPA entities are loaded and then bound to JNDI by the EJB3 deployer.  

So... I thought I would control the ordering of the Spring-JBoss MBean by tinkering with jboss-service.xml:


  | <server>
  |    	<mbean 
  | 		code="org.jboss.spring.deployment.SpringApplicationContextDeployer"
  | 		name="jboss.spring:service=SpringApplicationContextDeployer">
  | 
  | 		<depends>jboss.j2ee:service=EJB</depends>
  | 
  | 	</mbean>
  | </server>
  | 

This allowed the EJB entities to be loaded and bound to JNDI before the application context beans were loaded, and all was well.  Except that must have done something else somewhere because the WAR stopped loading properly.  

Is there a simple way to use PersistenceAnnotationBeanPostProcessor and JNDI to allow for multiple persistence units already initialized by the EJB3 deployer in JBoss? 

Thanks!

Saish 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4164567#4164567

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4164567



More information about the jboss-user mailing list