When using any of the hibernate versions 4.2.1 to 4.2.16, in the below code, inside callback session.doWork , after Iterator it.next() the associated dataSource to wrapper connection WrappedConnectionJDK6@25f1d9ee becomes NULL, subsequently stmt.executeQuery fails with exception "Connection is not associated with a managed connection.org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@25f1d9ee". We have configured JTA transaction manager, also aware of after_statement connection release mode, however same code with JTA transaction is working fine in hibernate versions 4.1.6 to 4.2.0.
Is this a new feature that now inside doWork callback we call not use connection (with JTA transaction) after Query.list/ Query.iterate.next or this is a longish bug?
try { Configuration configuration = new Configuration(); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.configure().getProperties()).buildServiceRegistry(); SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); final Session session = sessionFactory.getCurrentSession(); final PrintWriter writer = response.getWriter(); Transaction tx = session.beginTransaction(); session.doWork(new Work() { public void execute(Connection connection) throws SQLException { Iterator<ConfigurationScopeElement> it = session.getNamedQuery("suite.foundation.base.ConfigurationScope.getByCode").setCacheable(true).setParameter("code", "suite.default").iterate(); try { writer.print("<h2>ConfigurationScopeElement ID = " + it.next().getId() + "</h2></br> </br>"); }
catch(Exception e) { e.printStackTrace(); }
Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("select count from t_config_parm"); // Will fail here in Hibernate 4.2.15 with the error as in Summary line ,if previously called iterator it.next or query.list. while(rs.next()) { writer.print("<h2> Count of t_config_parm = " + rs.getString(1) + " </h2>"); }
rs.close(); stmt.close(); } }); tx.commit(); } catch (Exception e) { e.printStackTrace(); }
|