David, thanks so far. I tried the same thing and set up a simple test-project to play with the ejb-jar.xml My result is as follows:
Everything works as expected if I override the settings within the same jar. If I try to override the settings from the referenced jar, it does not work. Do you have any idea about this? I had to adjust the ejb-jar.xml as follows, so that the entityManager is injected correctly. I use the ejb-jar.xml within my original project. The referenced jar only has an ejb-jar with an empty <ejb-jar />-tag ---------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0" metadata-complete="true" > <enterprise-beans> <session> <ejb-name>CustomerManager2Impl</ejb-name> <business-local>company.CustomerManager2</business-local> <ejb-class>company.CustomerManager2Impl</ejb-class> <session-type>Stateless</session-type> <persistence-context-ref> <persistence-context-ref-name>em2</persistence-context-ref-name> <persistence-unit-name>IisTestPU2</persistence-unit-name> <injection-target> <injection-target-class>company.CustomerManager2Impl</injection-target-class> <injection-target-name>em</injection-target-name> </injection-target> </persistence-context-ref> </session> <session> <ejb-name>CustomerManagerImpl</ejb-name> <business-local>company.CustomerManager</business-local> <ejb-class>company.CustomerManagerImpl</ejb-class> <session-type>Stateless</session-type> <persistence-context-ref> <persistence-context-ref-name>em</persistence-context-ref-name> <persistence-unit-name>IisTestPU</persistence-unit-name> <injection-target> <injection-target-class>company.CustomerManagerImpl</injection-target-class> <injection-target-name>em</injection-target-name> </injection-target> </persistence-context-ref> </session> </enterprise-beans> </ejb-jar> ---------------------------------------------------------------- So if I copy the CustomerManager2Impl into the same jar, everything works fine, but as soon as I copy this into another jar and reference this jar, the deployment does not work anymore. Here comes the output: ---------------------------------------------------------------- 2009-02-23 12:58:10,141 INFO OpenEJB.startup:70 - openejb.home = C:\01-development\06-workspace\simpleEjbTest 2009-02-23 12:58:10,141 INFO OpenEJB.startup:70 - openejb.base = C:\01-development\06-workspace\simpleEjbTest 2009-02-23 12:58:10,141 DEBUG OpenEJB.startup:82 - Instantiating assembler class org.apache.openejb.assembler.classic.Assembler 2009-02-23 12:58:10,953 INFO OpenEJB.startup.config:70 - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) 2009-02-23 12:58:10,969 INFO OpenEJB.startup.config:70 - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) 2009-02-23 12:58:10,969 INFO OpenEJB.startup.config:70 - Configuring Service(id=My DataSource, type=Resource, provider-id=Default JDBC Database) 2009-02-23 12:58:10,969 INFO OpenEJB.startup.config:70 - Configuring Service(id=My Unmanaged DataSource, type=Resource, provider-id=Default JDBC Database) 2009-02-23 12:58:10,969 INFO OpenEJB.startup.config:70 - Configuring Service(id=My JMS Resource Adapter, type=Resource, provider-id=Default JMS Resource Adapter) 2009-02-23 12:58:10,969 INFO OpenEJB.startup.config:70 - Configuring Service(id=My JMS Connection Factory, type=Resource, provider-id=Default JMS Connection Factory) 2009-02-23 12:58:10,984 INFO OpenEJB.startup.config:70 - Configuring Service(id=gerdaDatabaseUnmanaged, type=Resource, provider-id=Default JDBC Database) 2009-02-23 12:58:10,984 INFO OpenEJB.startup.config:70 - Configuring Service(id=gerdaDatabase, type=Resource, provider-id=Default JDBC Database) 2009-02-23 12:58:10,984 INFO OpenEJB.startup.config:70 - Configuring Service(id=My CMP Container, type=Container, provider-id=Default CMP Container) 2009-02-23 12:58:10,984 INFO OpenEJB.startup.config:70 - Configuring Service(id=My BMP Container, type=Container, provider-id=Default BMP Container) 2009-02-23 12:58:10,984 INFO OpenEJB.startup.config:70 - Configuring Service(id=My Stateful Container, type=Container, provider-id=Default Stateful Container) 2009-02-23 12:58:11,000 INFO OpenEJB.startup.config:70 - Configuring Service(id=My Stateless Container, type=Container, provider-id=Default Stateless Container) 2009-02-23 12:58:11,000 INFO OpenEJB.startup.config:70 - Configuring Service(id=My MDB Container , type=Container, provider-id=Default MDB Container) 2009-02-23 12:58:11,000 DEBUG OpenEJB.startup.config:82 - Using openejb.deployments.classpath.include '' 2009-02-23 12:58:11,000 DEBUG OpenEJB.startup.config:82 - Using openejb.deployments.classpath.exclude '.*' 2009-02-23 12:58:11,000 DEBUG OpenEJB.startup.config:82 - Using openejb.deployments.classpath.filter.systemapps 'true' 2009-02-23 12:58:11,000 DEBUG OpenEJB.startup.config:82 - Using openejb.deployments.classpath.filter.descriptors 'false' 2009-02-23 12:58:11,000 DEBUG OpenEJB.startup.config:82 - Using openejb.deployments.classpath.require.descriptor 'false' 2009-02-23 12:58:11,109 DEBUG OpenEJB.startup.config:82 - Inspecting classpath for applications: 0 urls. 2009-02-23 12:58:11,234 INFO OpenEJB.startup.config:70 - Found EjbModule in classpath: C:\01-development\06-workspace\simpleEjbTest\target\classes 2009-02-23 12:58:11,344 INFO OpenEJB.startup.config:70 - Found EjbModule in classpath: C:\m2repo/test/1.0.0-SNAPSHOT/CustomerManager2Impl-1.0.0-SNAPSHOT.jar 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - URLs after filtering: 021 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/hibernate/ejb3-persistence/1.0.2.GA/ejb3-persistence-1.0.2.GA.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: file:/C:/01-development/06-workspace/simpleEjbTest/target/test-classes/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/testng/testng/5.8/testng-5.8-jdk15.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/slf4j/slf4j-log4j12/1.5.3/slf4j-log4j12-1.5.3.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/hibernate/hibernate-annotations/3.4.0.GA/hibernate-annotations-3.4.0.GA.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/hibernate/hibernate-core/3.3.1.GA/hibernate-core-3.3.1.GA.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: file:/C:/01-development/06-workspace/simpleEjbTest/target/classes/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/antlr/antlr/2.7.6/antlr-2.7.6.jar!/ 2009-02-23 12:58:11,359 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/hibernate/hibernate-commons-annotations/3.3.0.ga/hibernate-commons-annotations-3.3.0.ga.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/slf4j/slf4j-api/1.5.3/slf4j-api-1.5.3.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/apache/openejb/asm-finder/3.1/asm-finder-3.1.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/hibernate/hibernate-entitymanager/3.4.0.GA/hibernate-entitymanager-3.4.0.GA.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/javassist/javassist/3.4.GA/javassist-3.4.GA.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/oro/oro/2.0.8/oro-2.0.8.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/apache/openejb/commons-dbcp-all/1.3-r699049/commons-dbcp-all-1.3-r699049.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/apache/maven/surefire/surefire-api/2.4.3/surefire-api-2.4.3.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/org/apache/maven/surefire/surefire-booter/2.4.3/surefire-booter-2.4.3.jar!/ 2009-02-23 12:58:11,375 DEBUG OpenEJB.startup.config:82 - Descriptors path: jar:file:/C:/m2repo/test/1.0.0-SNAPSHOT/CustomerManager2Impl-1.0.0-SNAPSHOT.jar!/ 2009-02-23 12:58:11,375 INFO OpenEJB.startup.config:70 - Beginning load: C:\01-development\06-workspace\simpleEjbTest\target\classes 2009-02-23 12:58:11,391 DEBUG OpenEJB:82 - Deleted file C:\01-development\06-workspace\simpleEjbTest\temp\AppModule-49923 2009-02-23 12:58:11,391 DEBUG OpenEJB:82 - Deleted file C:\01-development\06-workspace\simpleEjbTest\temp\CustomerManager2Impl-1.0.0-SNAPSHOT-49922.jar 2009-02-23 12:58:11,391 DEBUG OpenEJB:82 - Deleted file C:\01-development\06-workspace\simpleEjbTest\temp 2009-02-23 12:58:11,391 INFO OpenEJB:70 - AntiJarLocking enabled. Using URL cache dir C:\01-development\06-workspace\simpleEjbTest\temp 2009-02-23 12:58:12,203 DEBUG OpenEJB:82 - Destroying classLoader urlclassloa...@7461949 2009-02-23 12:58:12,234 INFO OpenEJB.startup.config:70 - Beginning load: C:\m2repo/test/1.0.0-SNAPSHOT/CustomerManager2Impl-1.0.0-SNAPSHOT.jar 2009-02-23 12:58:12,266 DEBUG OpenEJB:82 - Coppied jar file to C:\01-development\06-workspace\simpleEjbTest\temp\CustomerManager2Impl-1.0.0-SNAPSHOT-38725.jar 2009-02-23 12:58:12,281 DEBUG OpenEJB:82 - Destroying classLoader urlclassloa...@6427893 2009-02-23 12:58:12,281 INFO OpenEJB.startup.config:70 - Configuring enterprise application: classpath.ear 2009-02-23 12:58:12,687 INFO OpenEJB:70 - Auto-deploying ejb CustomerManager2Impl: EjbDeployment(deployment-id=CustomerManager2Impl) 2009-02-23 12:58:12,687 INFO OpenEJB:70 - Auto-deploying ejb CustomerManagerImpl: EjbDeployment(deployment-id=CustomerManagerImpl) 2009-02-23 12:58:12,687 INFO OpenEJB:70 - Auto-deploying ejb CustomerManager2Impl: EjbDeployment(deployment-id=CustomerManager2Impl) 2009-02-23 12:58:12,703 INFO OpenEJB.startup.config:70 - Configuring PersistenceUnit(name=IisTestPU, provider=org.hibernate.ejb.HibernatePersistence) 2009-02-23 12:58:12,703 INFO OpenEJB.startup.config:70 - Configuring PersistenceUnit(name=IisTestPU2, provider=org.hibernate.ejb.HibernatePersistence) 2009-02-23 12:58:12,719 DEBUG OpenEJB.startup.config:82 - Adjusting PersistenceUnit(name=IisTestPU) property to hibernate.transaction.manager_lookup_class=org.apache.openejb.hibernate.TransactionManagerLookup 2009-02-23 12:58:12,719 DEBUG OpenEJB.startup.config:82 - Adjusting PersistenceUnit(name=IisTestPU2) property to hibernate.transaction.manager_lookup_class=org.apache.openejb.hibernate.TransactionManagerLookup 2009-02-23 12:58:12,734 ERROR OpenEJB.startup.validation:46 - FAIL ... CustomerManager2Impl: Persistence unit not found for @PersistenceContext(name="em", unitName=""). Available units [IisTestPU, IisTestPU2] ---------------------------------------------------------------- So do you have any idea what to do or what I missed here? Thanks in advance Thomas -----Ursprüngliche Nachricht----- Von: David Blevins [mailto:[email protected]] Gesendet: Freitag, 20. Februar 2009 08:46 An: [email protected] Betreff: Re: Override PersistenceContext On Feb 16, 2009, at 5:13 AM, <[email protected]> <[email protected] > wrote: > Hi @all, > > I´d like to override the settings for the PersistenceContext, but > somehow it does not work. > My Scenario is as follows: I´ve got a REFERENCED JAR and my local > project. The referenced jar contains some stateless services, with an > annotated EntityManager pointing to the default PersistenceContext > without declaring a unitName. > > Then I´ve got my project, which also has it´s own persistence.xml and > some services. As there are 2 persistence-units-defintions now, the > services from the referenced as well as those from my local project > fail to start, because injection does not work anymore. So far so > good! So I decided to override the persistenceUnit from the services > in the referencedJar and point them to a specific > persistence-unit-name. > The override looks perfect and I hacked up a test case to verify the overriding occurs as expected and all was fine. So there must be something else going on here. When we process annotations we actually update the descriptor that comes with the application and it is possible to set a flag so that it will be written back to disk allowing you to see the final and definitive set of metadata. Set the 'openejb.descriptors.output' flag to 'true' and scan the log output for the paths to the update ejb- jar.xml file(s). If what is going on doesn't become obvious, post the log output as well as the generated ejb-jar.xml. -David > > This is my business class from the referenced jar (where > CustomerManager is it´s local interface annotated with @Local): > ---------------------------------------------------------------------- > ------- > package company; > > @Stateless > public class CustomerManagerImpl implements CustomerManager { > > ... > @PersistenceContext > private EntityManager entityManager; ... > } > > ---------------------------------------------------------------------- > ------- > > Now I included an ejb-jar.xml in my /classes/META-INF directory within > my local project and redefined the EntityManager as follows: > > > ---------------------------------------------------------------------- > ------- <?xml version="1.0" encoding="UTF-8"?> <ejb-jar > xmlns="http://java.sun.com/xml/ns/javaee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://java.sun.com/xml/ns/javaee > http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd > " > version="3.0" > metadata-complete="true" > > <enterprise-beans> > <session> > <ejb-name>CustomerManagerImpl</ejb-name> > <business-local>company.CustomerManager</ > business-local> > <ejb-class>company.CustomerManagerImpl</ejb- > class> > <session-type>Stateless</session-type> > <persistence-context-ref> > <persistence-context-ref- > name>company.CustomerManagerImpl/entityManager</persistence-context- > ref-name> > <persistence-unit-name>IisTestPU</ > persistence-unit-name> > </persistence-context-ref> > </session> > </enterprise-beans> > </ejb-jar> > ---------------------------------------------------------------------- > ------- > > If I put anything wrong in this ejb-jar.xml I always receive an error. > So I assume, that the ejb-jar is interpreted correctly, but anyways I > receive an error when booting openEJB. > > ERROR - FAIL ... CustomerManagerImpl: The persistence unit "" does > not exist. Update the "entityManager" PersistenceContext ref to one > of the avail able units [CleoServicePU, IisTestPU] or declare the unit > in a persistence.xml like the following:<persistence > xmlns="http://java.sun.com/xml/ns/persi > stence" version="1.0"><persistence-unit name=""><jta-data- > source>java:openejb/Resource/myDataSource</jta-data-source><non-jta- > data-source>java:openejb > /Resource/myUnmanagedDataSource</non-jta-data- > source><properties><property name="openjpa.jdbc.SynchronizeMappings" > value="buildSchema(ForeignKeys=true > )"/></properties></persistence-unit></persistence> > > > Did I miss anything? > > Thomas >
