Hi all,
I'm trying to use DBCP with Hibernate, but it seems I can't bypass Hibernate's DriverManagerConnectionProvider.
I would like to avoid using the Hibernate properties file to configure the DB's url, password etc. To that end, I store the connection pool in JNDI (I use tomcat's JNDI implementation), where I define all its properties.
My problem is that when I build a session factory, the code ends up using the hibernate.connection properties from the hibernate.properties file I keep around for development to create a DriverManagerConnectionProvider. This file defines a JDBC driver that's not available in the production environemnt, so I get an exception.
I was hoping that this would work:
Code:
// Called once in the webapp's lifetime
init() {
// builds the configuration
cfg = new Configuration();
cfg.addClass(...);
cfg.addClass(...);
// Get the datasource from jndi
Context ctx = null;
ctx = new InitialContext();
m_datasource = (DataSource)ctx.lookup( "java:comp/env/jdbc/connectionPool");
// Build the session factory
m_sessionFactory = cfg.buildSessionFactory();
Session getSession(){
Connection conn = m_datasource.getConnection();
return m_sessionFactory.openSession(conn);
}
Is there a way I can make this work?
I guess I don't understand why cfg.buildSessionFactory() looks up the hibernate.connection.driver_class property
The reason why I don't want to configure dbcp in hibernates.properties (except during development) is that I want the application to be entirely congigured via JNDI.
Thanks for you help,
Susie.
Code: