I am using glassfish server with multiple jdbc connection pools. I want to have EntityManagerFactories for every jdbc connection.
Using the code
Map props = new HashMap();
props.put(PersistenceUnitProperties.JTA_DATASOURCE, <my jdbc datasource>);
Persistence.createEntityManagerFactory(<persistence unit name>, props);
Works fine but I cannot combine it with the UserTransation to have transaction begin and commit, rollback. Furthermore entityManager.getTrasnaction().begin, commit, rollback don’t work (I get records persisted in the database when an error occurs).
Things work great when I use UserTrasnaction and EntityManager injected with
@Resource
UserTransaction utx1;
@PersistenceContext(unitName = <persistence unit name>)
private EntityManager em1;
With the injection the utx1.begin(), utx1.commit() controls the entityManager perfectly! But the problem is that I cannot use my multiple jdbc connection pools that i have set up on my server.
So my question is: Can I do programmatically what this injection does?
@Resource
UserTransaction utx1;
@PersistenceContext(unitName = <persistence unit name>)
private EntityManager em1;
Thanx!
I have tried this, but it doesnt work
@Resource
UserTransaction utx1;
@PersistenceContext(
properties = {@PersistenceProperty(name=PersistenceUnitProperties.JTA_DATASOURCE, value="ORCLH_MARMA")},
unitName = "MINLO")
private EntityManager em1;