# Opening a Session with a user-provided connection in 5.6.1

**URL:** <https://discourse.hibernate.org/t/opening-a-session-with-a-user-provided-connection-in-5-6-1/5909>\
**Category:** Hibernate ORM\
**Created:** [December 13, 2021, 9:48pm UTC](https://discourse.hibernate.org/t/opening-a-session-with-a-user-provided-connection-in-5-6-1/5909 "2021-12-13T21:48:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbruemmer](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/hbruemmer/32/1736_2.png) [@hbruemmer](https://discourse.hibernate.org/u/hbruemmer)\
**Post date:** [December 13, 2021, 9:48pm UTC](https://discourse.hibernate.org/t/opening-a-session-with-a-user-provided-connection-in-5-6-1/5909/1 "2021-12-13T21:48:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [December 14, 2021, 8:38am UTC](https://discourse.hibernate.org/t/opening-a-session-with-a-user-provided-connection-in-5-6-1/5909/2 "2021-12-14T08:38:29Z")

</div>

Please create an issue in the issue tracker([https://hibernate.atlassian.net](https://hibernate.atlassian.net)) with a test case([hibernate-test-case-templates/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java)) that reproduces the issue.
