How to make Spring load a JDBC Driver BEFORE initializing Hibernate's SessionFactory?

Posted by Bill_BsB on Stack Overflow See other posts from Stack Overflow or by Bill_BsB
Published on 2010-05-11T15:04:22Z Indexed on 2010/05/11 15:14 UTC
Read the original article Hit count: 214

Filed under:
|
|
|

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:

  1. Custom Database initializes
  2. Spring load beans from web.xml
  3. Spring loads ServletBeans(applicationContext.xml)
  4. Hibernate kicks in: shows version and all the properties correctly loaded.
  5. Hibernate's HbmBinder runs (maps all my classes)
  6. LocalSessionFactoryBean - Building new Hibernate SessionFactory
  7. DriverManagerConnectionProvider - using driver: MyCustomJDBCDriver at CustomDBURL
  8. I get a SQLException: No suitable driver found for CustomDBURL
  9. Hibernate loads the Custom Dialect
  10. My CustomJDBCDriver finally gets registered with DriverManager (log messages)
  11. SettingsFactory runs
  12. SchemaExport runs (hbm2ddl)
  13. I get a SQLException: No suitable driver found for CustomDBURL (again?!)
  14. 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.

© Stack Overflow or respective owner

Related posts about spring

Related posts about hibernate