tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cole Ferrier <cole.ferr...@gmail.com>
Subject Different behavior - Tomee Plus 7.0.3 vs Tomee plume 7.0.3 - JTA managed database connections
Date Tue, 25 Apr 2017 14:53:14 GMT
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.

Mime
View raw message