Two db connections using ejb, java persistence entitymanager
I am am tryign to access two dbs via one slsb, specifically one method within an slsb. However this is not possible ? Other than altering the stored procs is there anything else I could do ?
@PersistenceContext(unitName = "DB开发者_运维技巧1")
private EntityManager oneEntityManager;
@PersistenceContext(unitName = "DB2")
private EntityManager twoEntityManager;
...
StringBuilder queryString1 = new StringBuilder("exec myProc1 ");
Query queryOne = oneEntityManager.createNativeQuery(queryString.toString());
List<?> resultListOne = query.getResultList();
StringBuilder queryString2 = new StringBuilder("exec myProc2 ");
Query queryTwo = twoEntityManager.createNativeQuery(queryString2.toString());
List<?> resultListTwo = queryTwo.getResultList();
...
causes : org.hibernate.exception.GenericJDBCException: Cannot open connection
I am am tryign to access two dbs via one slsb, specifically one method within an slsb. However this is not possible?
This is definitely possible but it would really help to give more details:
- are you accessing different databases?
- can you show the configuration of your persistence units?
- can you tell us how your configured your datasource (XA?)
- can you show how you annotated the method of your SLSB?
causes : org.hibernate.exception.GenericJDBCException: Cannot open connection
This suggests a configuration problem for one of your persistence unit but it's impossible to say more.
精彩评论