I have an application that requires me to start the Hibernate session with an externally provided JDBC connection. The following code worked to establish the Hibernate session with a provided JDBC connection in Hibernate 5.4.23.
SessionBuilder sb = HibernateConfig.getSessionFactory().withOptions();
(In separate class HibernateConfig, this is the main line in the getSessionFactory() method:
…
SessionFactory factory = new Configuration().configure().buildSessionFactory();
…
)
Session session = sb.connection(connection).openSession();
I am attempting to update to the latest version (5.6.1), and I now receive the following error on the call to ‘buildSessionFactory’:
java.lang.UnsupportedOperationException: The application must supply JDBC connections
at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:44)
What changed between 5.4.23 and 5.6.1, and how do I do this correctly under the latest version?