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.
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