We are working in release mode = AFTER STATEMENT.
The intention is that after each statement the connection is released, and can be reused later within the same thread / transaction by directly accessing a datasource.
It worked this way with Hibernate 5.
However, as with Hibernate 6, it goes to DeferredResultSetAccess.executeQuery()
And the code there is written as such:
Hi there, thanks for reporting this problem. Could you please try to create a reproducer for this problem with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.
The reproducer is attached.
The idea of the test is as follows: Since both connection requests come from the same thread, Atomikos is expected to bring the same connection, unless it is currently in use (regardless of being in transaction). Closing a connection does not close the transaction, it only returns the connection to the pool. Connection pool max size is set to 1, this way we ensure we consume only one connection. As long as a connection is closed after statement, it works OK. The problematic parts is find(), since it does not close the connection. Thus, the next connection request fails, and the test fails. The test works OK on Hibernate 5.
Please check this is wirtten in a proper form, and you can proceed with this (before the formal call is open). Thanks.
package hibernateTest;
import static org.junit.Assert.assertEquals;
import java.sql.Connection;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import org.h2.jdbcx.JdbcDataSource;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.atomikos.jdbc.AtomikosDataSourceBean;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Id;
import jakarta.persistence.Persistence;
import jakarta.persistence.Table;
/**
* This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
*/
public class HibernateTest {
private EntityManagerFactory entityManagerFactory;
private AtomikosDataSourceBean dataSource;
@Before
public void init() {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1");
ds.setUser("sa");
dataSource = new AtomikosDataSourceBean();
dataSource.setXaDataSource(ds);
dataSource.setDefaultIsolationLevel(Connection.TRANSACTION_READ_COMMITTED);
dataSource.setUniqueResourceName("resourceName");
dataSource.setMaxPoolSize(1);
Map<String, Object> properties = new HashMap<>();
properties.put(AvailableSettings.DATASOURCE, dataSource);
properties.put(AvailableSettings.CONNECTION_HANDLING, PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT);
entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU", properties);
}
@After
public void destroy() {
entityManagerFactory.close();
}
// Entities are auto-discovered, so just add them anywhere on class-path
// Add your tests, using standard JUnit.
@Test
public void hhh123Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
A entity = new A();
entity.setX(0);
entity.setY(0);
entityManager.persist(entity);
entityManager.flush();
entityManager.find(A.class, 1);
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
) {
statement.execute("UPDATE A SET Y = 1 WHERE X = 0");
assertEquals(1, statement.getUpdateCount());
}
entityManager.getTransaction().commit();
entityManager.close();
}
@Entity
@Table(name = "A")
public static class A {
@Id
private Integer x;
private Integer y;
public Integer getX() {
return x;
}
public void setX(Integer x) {
this.x = x;
}
public Integer getY() {
return y;
}
public void setY(Integer y) {
this.y = y;
}
}
}
If anyone has time to work on this, you will receive a notification from Jira. Since you created the issue, you are registered as watcher, so any changes that happen will cause e.g. an email notification.
I see it was fixed, many thanks.
When is the version expected to be released?
Is there anyway to receive any version (not necessary the official release) to check it resolves our problem?
Thanks.
@avraham.nissimov version 6.2 is only receiving limited support, the issue was fixed in version 6.4.5 as well so I suggest upgrading as soon as possible.
version 6.5 .0.CR2 where it was fixed introduced many other critical problems
Could you please expand on this? If you found problems with the new version please also report them with an attached reproducer in our issue tracker and we’ll look into them.