openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chintan4181 <chintan4...@gmail.com>
Subject How to find entity belong which EntityManger?
Date Mon, 13 Jun 2011 16:53:25 GMT
Hello All

In our project we are using JPA2.0 with two persistence units. I have two
persistence manager and able to initialize successfully on IBM WAS. I am
using RSA 8.0 to generate the entities. we have two database one is SQL
server and another on is DB2. My requirement is before calling persist
method on EntityManager i have first choose the EntityManager in other words
how to make sure that Entity/Table belongs to SQLServer or DB2 below API's
are returning false

@PersistenceContext(unitName="MIApplicationSQL")
private EntityManager emSqlServer; 

@PersistenceContext(unitName="MIApplicationDB2")
private EntityManager emDB2;

private EntityManager getEntityManager(FwrkDO fnDO) {

EntityManager em = null; 

// emSqlServer is an EntityManager for SQL server
// emDB2 is an EntityManager for Db2
//fndo is an entity which need to be validated 

Set&lt;EntityType&lt;?&gt;> entities = emDB2.getMetamodel().getEntities();
Set&lt;EntityType&lt;?&gt;> entities2 =
emSqlServer.getMetamodel().getEntities();

// contains method returns false 
if (entities2.contains(fnDO)) {
em = emSqlServer;
} else if (entities.contains(fnDO)) {
em = emDB2;
} 

// EntityManager.contains also returning false
if (emSqlServer.contains(fnDO)) {
em = emSqlServer;
} else if (emDB2.contains(fnDO)) {
em = emDB2;
}
return em;
}

How to ensure the entity/table is belongs to SQLServer or DB2 server.
 


--
View this message in context: http://openjpa.208410.n2.nabble.com/How-to-find-entity-belong-which-EntityManger-tp6470903p6470903.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message