Hi
I have two web projects which have part of their sources shared. I do this by a
third Project as a Webfragment and deploy it together with each Project in the
lib dir of the war-File.
Each web project has its own Persistentunit defined in persistence.xml. Some of
the Entitys are Classes of the Webfragment which I reference by the fallowing
Tag: <jar-file>../lib/AllWebBase.jar</jar-file>.
Per Persistanceunite there is a Resource defined in the tomee.xml.
As far as I deploy just one of the Project to the TomEE (1.5.1-45) everything
is OK and works as expected. But If I deploy the two Projects on the same
TomEE, the Databaseresources are getting mixed. Most of the Requests und
Updates are flow through the Resource referenced by the Project first loaded.
Can some One give me a Hint, watt's probably miss configured or even doesn't
work?
tomee.xml (Part)
<Resource id="jdbc/sheep" type="DataSource">
DataSourceCreator tomcat
JtaManaged true
JdbcDriver oracle.jdbc.OracleDriver
JdbcUrl <The URL>
UserName <The DatabaseUser>
Password <The Password>
ConnectionProperties v$session.program=08_Schafe;
InitialSize 2
MinIdle 2
MaxActive 10
MaxIdle 10
</Resource>
<Resource id="jdbc/goat" type="DataSource">
DataSourceCreator tomcat
JtaManaged true
JdbcDriver oracle.jdbc.OracleDriver
JdbcUrl <The URL>
UserName <The DatabaseUser>
Password <The Password>
ConnectionProperties v$session.program=07_Ziegen;
InitialSize 2
MinIdle 2
MaxActive 10
MaxIdle 10
</Resource>
Persistence.xml (Project One)
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd<http://java.sun.com/xml/ns/persistence%20http:/java.sun.com/xml/ns/persistence/persistence_2_0.xsd>">
<persistence-unit name="GoatWeb">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/goat</jta-data-source>
<jar-file>../lib/AllWebBase.jar</jar-file>
<properties>
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.target-database" value="Oracle11" />
<property name="accessToUnderlyingConnectionAllowed" value="true" />
</properties>
</persistence-unit>
</persistence>
Persistence.xml (Project Two)
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd<http://java.sun.com/xml/ns/persistence%20http:/java.sun.com/xml/ns/persistence/persistence_2_0.xsd>">
<persistence-unit name="SheepWeb">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/sheep</jta-data-source>
<jar-file>../lib/AllWebBase.jar</jar-file>
<properties>
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.target-database" value="Oracle11" />
<property name="accessToUnderlyingConnectionAllowed" value="true" />
</properties>
</persistence-unit>
</persistence>
DatabaseProducer.java
public class DatabaseProducer implements Serializable {
private static final long serialVersionUID = 6208984760382814601L;
@PersistenceUnit
private EntityManagerFactory emFactory;
@PersistenceContext
private EntityManager em;
@Inject
private UserDatabase userDB;
@Produces
@Default
@RequestScoped
public EntityManager createSimpleEntityManager() {
return em;
}
@Produces
@Proxied
@RequestScoped
public EntityManager createProxiedEntityManager() {
if(userDB.isDbUser()) {
Map<String, Object> props = new HashMap<String,
Object>();
props.put("eclipselink.oracle.proxy-type",
OracleConnection.PROXYTYPE_USER_NAME);
props.put(OracleConnection.PROXY_USER_NAME,
userDB.getDbUsername());
return emFactory.createEntityManager(props);
}
return emFactory.createEntityManager();
}
}
Best Regards
Martin Berner