In the process of porting some C++ code to Java I’m in the need of calling a stored procedure with in/out parameters.
As I cannot change this procedure (e.g. to work with hibernate and em.createNativeQuery) I guess I’ll have to unwrap the hibernate session from the EntityManager to get hold of the underlying jdbc connection.
My question now is will this connection participate in the Container Managed Transaction started by the EJB-Container (JBoss AS 7.1) or will I have to manually manage transactions in this case?
The connection associated with the Hibernate session/EntityManager is associated with the current transaction context. Since the container has already started a JTA transaction (assuming that is the case here), you wouldnt need to manually manage transactions.
There is however a different problem that you may have to manage – the transaction-level cache and cache synchronization with other caches. If the invocation of the stored procedure updates the database in a way that renders the caches stale, then you’ll need to clear their contents out. Sometimes you may need to clear out only certain entries, and other times it may be the entire cache itself; all of this depends on what type of entries are rendered stale.