What's the official way to do this?
I'm using the following code to configure Hibernate:
Code:
Configuration config = new Configuration().configure("/hibernate.cfg.xml");
SessionFactory sessionFactory = config.buildSessionFactory();
From there hibernate just deals with all the JDBC crap and everything goes along just swimmingly.
But now I have to get my hands dirty with a direct JDBC connection.
Given this configuration setup, what's the best way to get a direct JDBC connection?
I figure the best thing to do is get the ConnectionProvider Hibernate is using, because (a) it seems obvious and (b) one day I'm going to need to get the ConnectionProvider in order to register a Proxool lifecycle listener.
I can do dodgy things like:
Cast SessionFactory to SessionFactoryImplementor and then call getConnectionProvider() (this is how our app does it currently, but it makes me feel dirty so I want to find a Better Way).
Register our Custom ConnectionProvider subclass with a singleton and then call that to get connections.
But how am I
supposed to do this?
I don't particularly want to create/close a session just to use it's connection, or is that "the" way to do it?