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


Reply via email to