Hi if the datasource is a JtaManaged=true one and the persistence unit a JTA one (seems so) then it should reuse the same connection which is stored in the transaction registry. Do you have a github sample reproducing this issue (with a failing test or tomee-maven-plugin set up)?
Romain Manni-Bucau @rmannibucau <https://twitter.com/rmannibucau> | Blog <https://blog-rmannibucau.rhcloud.com> | Old Blog <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> | LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory <https://javaeefactory-rmannibucau.rhcloud.com> 2017-04-25 16:53 GMT+02:00 Cole Ferrier <cole.ferr...@gmail.com>: > I have a need to be able to run a custom native sql command against the > same > connection that is being used for a JPA query. > > i have a JTAManaged datasource declared in my resources.xml, it is > referenced in a persistence.xml for JPA. > > @Path("/foo") > @Stateless > public class Foo { > > @PersistenceContext(unitName = "foo") > private EntityManager entityManager; > > @Resource(name = "foo/myDatabase") > private javax.sql.DataSource myDB; > > @GET > public DataObj getAll() { > > DataObj result = null; > > try { > > Connection connection = myDB.getConnection(); > > //actual alter session statement ommitted > PreparedStatement ps = > connection.prepareStatement("ALTER SESSION > STATEMENT"); > ps.execute(); > ps.close(); > > TypedQuery<DataObj> query = > entityManager.createNamedQuery("DataObj.findAll", DataObj.class); > result = query.getSingleResult(); > > } catch (Exception exception) { > exception.printStackTrace(); > > } > > return result; > } > } > > this code works in tomee Plus, as this is a JTA managed transaction, i get > the same connection for both the direct database connection that is > injected > and for the connection that is used by JPA. > > If i deploy this to tomee plume (eclipse link).. i believe it is using two > different connections. > > when i read: > http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_ > Connection_from_an_EntityManager > > it makes me think the behavior should be the same with eclipselink. > > let me know what further information you would want. and how i can provide. > > > > -- > View this message in context: http://tomee-openejb.979440. > n4.nabble.com/Different-behavior-Tomee-Plus-7-0-3-vs- > Tomee-plume-7-0-3-JTA-managed-database-connections-tp4681596.html > Sent from the TomEE Users mailing list archive at Nabble.com. >