How to make Spring load a JDBC Driver BEFORE initializing Hibernate's SessionFactory?
- by Bill_BsB
I'm developing a Spring(2.5.6)+Hibernate(3.2.6) web application to connect to a custom database. For that I have custom JDBC Driver and Hibernate Dialect. I know for sure that these custom classes work (hard coded stuff on my unit tests).
The problem, I guess, is with the order on which things get loaded by Spring.
Basically:
Custom Database initializes
Spring load beans from web.xml
Spring loads ServletBeans(applicationContext.xml)
Hibernate kicks in: shows version and all the properties correctly loaded.
Hibernate's HbmBinder runs (maps all my classes)
LocalSessionFactoryBean - Building new Hibernate SessionFactory
DriverManagerConnectionProvider - using driver: MyCustomJDBCDriver at CustomDBURL
I get a SQLException: No suitable driver found for CustomDBURL
Hibernate loads the Custom Dialect
My CustomJDBCDriver finally gets registered with DriverManager (log messages)
SettingsFactory runs
SchemaExport runs (hbm2ddl)
I get a SQLException: No suitable driver found for CustomDBURL (again?!)
Application get successfully deployed but there are no tables on my custom Database.
Things that I tried so far:
Different techniques for passing hibernate properties: embedded in the 'sessionFactory' bean, loaded from a hibernate.properties file. Nothing worked but I didn't try with hibernate.cfg.xml file neither with a dataSource bean yet.
MyCustomJDBCDriver has a static initializer block that registers it self with the DriverManager.
Tried different combinations of lazy initializing (lazy-init="true") of the Spring beans but nothing worked.
My custom JDBC driver should be the first thing to be loaded - not sure if by Spring but...!
Can anyone give me a solution for this or maybe a hint for what else I could try? I can provide more details (huge stack traces for instance) if that helps.
Thanks in advance.