Hello,
I am using Hibernate 3.1 in Jboss 4.0.3.
I have to execute a lot of native update queries from within a stateless BMT Session bean.
I am following the suggestions in this thread, but have the impression that the queries are not executed within the current transaction scope.
Here's my code for executing native SQL. The session has been passed as a parameter to the method where this is executed and has been bound to the current user transaction (I checked the server log).
Code:
Connection conn = session.connection();
PreparedStatement stmt = conn.prepareStatement(sql);
//Set params ...
stmt.executeUpdate();
If I don't use native SQL, then the whole application runs fine, and there are no warnings of any kind in my log files. But as soon as a native SQL query is executed by the code above, I get the following warnings in my server log:
- org.hibernate.jdbc.JDBCContext: opening user JDBC connection, application must close it
- org.jboss.resource.connectionmanager.CachedConnectionManager: Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@1bda6a0
- org.jboss.resource.connectionmanager.TxConnectionManager: Prepare called on a local tx. Use of local transactions on a jta transaction with more than one branch may result in inconsistent data in some cases of failure.
Could someone tell me how I can execute a native SQL query using hibernate within the current JTA transaction? Because now I fear they fall outside of that scope (those warnings above really make me feel uncomfortable with my current solution).
And should I close those connections myself or will closing them myself cause them to be commited outside of the current JTA transaction?
All hints and solutions are welcome.
Thanks a lot.
Luc Feys