views:

211

answers:

1

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.

+1  A: 

If Hibernate is responsible for getting database connections, then the hibernate properties needs to include the hibernate.connection.driver_class property.

In your case:

hibernate.connection.driver_class = CustomJDBCDriver 
skaffman
Hi skaffman,I have included the driver_class exactly the way you said - and I can see it gets loaded on Hibernate log - and the driver gets loaded and registered with the DriverManager. So that's not the answer to my question yet.Thanks anyway.
Bill_BsB