[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [eclipselink-dev] Loading multiple persistence.xml files
|
Carl,
Hi, I just happened to have tested a one particular
use-case configuration similar to your yesterday on WebLogic
10.3.
Using two (2) persistence units on the same
persistence.xml in the same ejb.jar I seem to work fine.
The servlet client is able to persist and query on two sets
of entites (that happend to have the same name but different packages) from two
physically different JTA datasources.
The key to getting this scenario to work was including the
element...
<exclude-unlisted-classes>true</exclude-unlisted-classes>
...so that I did not pick up the other entity on the
classpath when parsing the first during "alias" narrowing - and
vice-versa.
See the following wiki link that details some of the
configuration and shows a screen capture of both sets of
entities.
Q) What types of
logs to you get on the predeploy() for each persistence unit on logging level
FINEST - this may shed some light on why your first PU's entities are
missed?
thank you
/michael
-----------------details---------------------------
2
container managed persistence units used (the 3rd is only used for DDL
generation on an SE client)
<persistence
version="1.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_1_0.xsd">
<persistence-unit name="exampleDuplicate" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>remoteJTA</jta-data-source>
<class>org.eclipse.persistence.example.jpa.server.entity.Cell</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="WebLogic_10"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<!-- property
name="eclipselink.orm.validate.schema"
value="false"/-->
</properties>
</persistence-unit>
<persistence-unit name="example"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>localJTA</jta-data-source>
<class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="WebLogic_10"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<!-- property
name="eclipselink.orm.validate.schema"
value="false"/-->
</properties>
</persistence-unit>
<persistence-unit name="exampleLocal"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="eclipselink.jdbc.platform" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
<property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
<property name="eclipselink.jdbc.user" value="scott"/>
<property name="eclipselink.jdbc.password" value="pw"/>
<!-- property
name="eclipselink.logging.logger"
value="JavaLogger"/-->
<!-- turn on
table generation only to initialize db and then disable the two elements below
-->
<!-- property
name="eclipselink.ddl-generation"
value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/-->
</properties>
</persistence-unit>
</persistence>
In the
case of using both persistence units I get 2 sets of 4 logs = 8 for the 4
connections to the 2 datasources
The two datasources in my case are Oracle11g
(remoteJTA) and Oracle10g (localJTA) - both using the same 11g driver - so it is
easier to tell them apart in the logs.
When i
use the exampleDuplicate persistence unit i get a login for the first Oracle 10g
based datasource (remoteJTA)
EL
Config: 2008.12.15
15:43:56.419--ServerSession(3303389)--Connection(28810575)--Thread(Thread[)--Connected:
jdbc:oracle:thin:@127.0.0.1:1521:orcl
User: SCOTT
Database: Oracle
Version: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, OLAP, Data Mining and Real Application
Testing options
Driver: Oracle JDBC driver Version:
11.1.0.7.0-Production
EL Config: 2008.12.15
15:43:56.419--ServerSession(3303389)--Connection(28892307)--Thread(Thread[)--connecting(DatabaseLogin(
platform=>Oracle10Platform
user
name=> ""
connector=>JNDIConnector datasource
name=>null
))
and
the persist call for the first set of entities in the first persistence
unit
Later
when using the Oracle 11g based datasource (localJTA)
EL Config: 2008.12.15
15:43:56.966--ServerSession(25279766)--Connection(6794127)--Thread(Thread[)--Connected:
jdbc:oracle:thin:@10.156.53.19:1521:orcl
User: SCOTT
Database: Oracle
Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 -
Production
With the Partitioning, OLAP and Data Mining options
Driver:
Oracle JDBC driver Version: 11.1.0.7.0-Production
EL Config: 2008.12.15
15:43:56.966--ServerSession(25279766)--Connection(3176465)--Thread(Thread[)--connecting(DatabaseLogin(
platform=>Oracle10Platform
user
name=> ""
connector=>JNDIConnector datasource name=>null
))
The servlet client uses two stateless session beans for entitymanager
access
public class FrontController extends HttpServlet implements Servlet
{
@EJB(beanName="ApplicationService")
public
ApplicationServiceLocal applicationService;
@EJB(beanName="ApplicationService2")
public
ApplicationServiceLocal2 applicationService2;
...
// Later I must fully reference my entities because in
this case they have the same class name in different
packages
List<org.eclipse.persistence.example.jpa.server.business.Cell> rowsList =
(List<org.eclipse.persistence.example.jpa.server.business.Cell>)getApplicationService().query("select
object(e) from Cell e");
List<org.eclipse.persistence.example.jpa.server.entity.Cell> rowsList2 =
(List<org.eclipse.persistence.example.jpa.server.entity.Cell>)getApplicationService2().query("select
object(e) from Cell e");
Each entitymanager is injected into the stateless session beans
package org.eclipse.persistence.example.jpa.server.entity;
@Local
@Stateless
public class ApplicationService implements ApplicationServiceLocal
{
@PersistenceContext(unitName="example",
type=PersistenceContextType.TRANSACTION)
private EntityManager
entityManager;
package org.eclipse.persistence.example.jpa.server.entity;
@Local
@Stateless
public class ApplicationService2 implements
ApplicationServiceLocal2
{
@PersistenceContext(unitName="exampleDuplicate",
type=PersistenceContextType.TRANSACTION)
private EntityManager
entityManager;
Both versions of the Cell entity (in different packages but with the
same schema on different databases) are located on the ejb.jar along with the
session beans
package
org.eclipse.persistence.example.jpa.server.entity;
@Entity
@Table(name="EL_CELL")
public
class Cell implements Serializable {
package
org.eclipse.persistence.example.jpa.server.business;
@Entity
@Table(name="EL_CELL")
public
class Cell implements Serializable {
I
have a setup where multiple project come into a shared classloader. Each
project can have its own model files and thusly its own persistence.xml and
orm.xml files. When I create an EntityManager, I see in the logs that
each persistence.xml file is found (3) and each orm.xml file loads with the
expected entities. When I try to query or persist using this
EntityManager, only the entities from the lastly loaded persistence.xml is
found. Am I loading this correctly? Am I trying to access things
incorrectly?