3 Replies Latest reply on Jan 19, 2006 6:37 AM by Mark Torrens

    Multiple EntityManagers

    Mark Torrens Newbie

      I've been trying now for sometime to get a second EntityManager to deploy successfully using EJB 3.0 and JBoss 4.0.3 SP1.

      My second EntityManager references existing Entities and a second database. The pesistence.xml for my second EntityManager is as follows:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <entity-manager>
      
       <name>open4ejbempublished</name>
       <jta-data-source>java:/inmezzo2published</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.show_sql" value="false" />
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
       <property name="hibernate.cache.provider_class" value="org.jboss.ejb3.entity.TreeCacheProviderHook"/>
       <property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache"/>
       </properties>
      
       <class>com.inmezzo.entity.AuditService</class>
       <class>com.inmezzo.entity.DatabaseConnection</class>
       <class>com.inmezzo.entity.Deployment</class>
       <class>com.inmezzo.entity.DeploymentPolicy</class>
       <class>com.inmezzo.entity.Domain</class>
       <class>com.inmezzo.entity.Field</class>
       <class>com.inmezzo.entity.FieldFieldGetter</class>
       <class>com.inmezzo.entity.FieldGetter</class>
       <class>com.inmezzo.entity.Policy</class>
       <class>com.inmezzo.entity.PolicyGroup</class>
       <class>com.inmezzo.entity.SampleData</class>
       <class>com.inmezzo.entity.Service</class>
       <class>com.inmezzo.entity.ServiceNode</class>
       <class>com.inmezzo.entity.ServiceServiceNode</class>
       <class>com.inmezzo.entity.SQLGetter</class>
       <class>com.inmezzo.entity.URL</class>
       <class>com.inmezzo.entity.User</class>
       <class>com.inmezzo.entity.WebServiceService</class>
       <class>com.inmezzo.entity.XMLGetter</class>
      
      </entity-manager>
      


      The datasource inmezzo2published does deploy successfully when the datasource xml file is copied to the JBoss deploy directory.

      The second EntityManager is stored in a par file called entitiespublished.par. The entitiespublished.par file only contains the persistence.xml file as shown below.

      <!-- Package the persistence module for publishing -->
      <target name="package-published-par" depends="compile">
       <jar jarfile="${build.dir}/jar/entitiespublished.par">
       <metainf dir="dd/persistence">
       <include name="persistencepublished.xml"/>
       </metainf>
       </jar>
      </target>
      


      The application.xml file is shown below. The entities.par file shown below contains all the entities.

      <?xml version="1.0" encoding="UTF-8"?>
      <application version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
      
       <display-name>Open4EJB</display-name>
      
       <module>
       <ejb>entities.par</ejb>
       </module>
      
       <module>
       <ejb>entitiespublished.par</ejb>
       </module>
      
       <module>
       <ejb>Open4EJB.jar</ejb>
       </module>
      
       <module>
       <ejb>business.ejb3</ejb>
       </module>
      
      </application>
      


      The Second EntityManager is referenced as follows:

      import java.util.List;
      
      import javax.annotation.Resource;
      import javax.annotation.security.RolesAllowed;
      import javax.ejb.Remote;
      import javax.ejb.SessionContext;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.annotation.security.SecurityDomain;
      
      import com.inmezzo.audit.AuditService;
      import com.inmezzo.entity.Deployment;
      import com.inmezzo.entity.Domain;
      import com.inmezzo.remote.DeploymentDAO;
      
      @Stateless
      @Remote( { DeploymentDAO.class } )
      @SecurityDomain( "open4ejb" )
      public class DeploymentDAOBean implements DeploymentDAO
      {
       @Resource SessionContext ctx;
       @PersistenceContext(unitName = "open4ejbem")
       protected EntityManager em;
      
       @PersistenceContext(unitName = "open4ejbempublished")
       protected EntityManager em2;
      
       ...
      


      The Deployment error is as follows:

      2006-01-09 13:20:52,522 DEBUG [org.jboss.ejb3.stateless.StatelessManager] Starting failed jboss.j2ee:service=EJB3,name=com.inmezzo.session.DeploymentDAOBean
      java.lang.RuntimeException: unable to find: java:/managedEntityFactories/open4ejbempublished
       at org.jboss.ejb3.injection.PersistenceContextHandler.getManagedEntityManagerFactory(PersistenceContextHandler.java:85)
       at org.jboss.ejb3.injection.PersistenceContextHandler.loadFieldInjectors(PersistenceContextHandler.java:169)
       at org.jboss.ejb3.injection.PersistenceContextHandler.loadInjectors(PersistenceContextHandler.java:134)
       at org.jboss.ejb3.EJBContainer.resolveInjectors(EJBContainer.java:397)
       at org.jboss.ejb3.EJBContainer.initializePool(EJBContainer.java:330)
       at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:283)
       at org.jboss.ejb3.SessionContainer.start(SessionContainer.java:48)
       at org.jboss.ejb3.stateless.StatelessContainer.start(StatelessContainer.java:63)
       at org.jboss.ejb3.stateless.StatelessManager.startService(StatelessManager.java:93)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:274)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:230)
       at sun.reflect.GeneratedMethodAccessor270.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:943)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:428)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy465.start(Unknown Source)
       at org.jboss.ejb3.Ejb3JmxDeployment.start(Ejb3JmxDeployment.java:258)
       at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:39)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:274)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:230)
       at sun.reflect.GeneratedMethodAccessor270.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:943)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:428)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy10.start(Unknown Source)
       at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:228)
       at sun.reflect.GeneratedMethodAccessor230.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy11.start(Unknown Source)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:989)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:979)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:790)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:753)
       at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy6.deploy(Unknown Source)
       at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:319)
       at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:489)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:192)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:203)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:182)
      Caused by: javax.naming.NameNotFoundException: open4ejbempublished not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:255)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.jboss.ejb3.injection.PersistenceContextHandler.getManagedEntityManagerFactory(PersistenceContextHandler.java:81)
       ... 89 more
      2006-01-09 13:20:52,522 WARN [org.jboss.system.ServiceController] Problem starting service jboss.j2ee:service=EJB3,name=com.inmezzo.session.DeploymentDAOBean
      java.lang.RuntimeException: unable to find: java:/managedEntityFactories/open4ejbempublished
       at org.jboss.ejb3.injection.PersistenceContextHandler.getManagedEntityManagerFactory(PersistenceContextHandler.java:85)
       at org.jboss.ejb3.injection.PersistenceContextHandler.loadFieldInjectors(PersistenceContextHandler.java:169)
       at org.jboss.ejb3.injection.PersistenceContextHandler.loadInjectors(PersistenceContextHandler.java:134)
       at org.jboss.ejb3.EJBContainer.resolveInjectors(EJBContainer.java:397)
       at org.jboss.ejb3.EJBContainer.initializePool(EJBContainer.java:330)
       at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:283)
       at org.jboss.ejb3.SessionContainer.start(SessionContainer.java:48)
       at org.jboss.ejb3.stateless.StatelessContainer.start(StatelessContainer.java:63)
       at org.jboss.ejb3.stateless.StatelessManager.startService(StatelessManager.java:93)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:274)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:230)
       at sun.reflect.GeneratedMethodAccessor270.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:943)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:428)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy465.start(Unknown Source)
       at org.jboss.ejb3.Ejb3JmxDeployment.start(Ejb3JmxDeployment.java:258)
       at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:39)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:274)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:230)
       at sun.reflect.GeneratedMethodAccessor270.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:943)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:428)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy10.start(Unknown Source)
       at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:228)
       at sun.reflect.GeneratedMethodAccessor230.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy11.start(Unknown Source)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:989)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:979)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:790)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:753)
       at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
       at $Proxy6.deploy(Unknown Source)
       at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:319)
       at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:489)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:192)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:203)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:182)
      Caused by: javax.naming.NameNotFoundException: open4ejbempublished not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:255)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.jboss.ejb3.injection.PersistenceContextHandler.getManagedEntityManagerFactory(PersistenceContextHandler.java:81)
       ... 89 more