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.

Bill_BsB
  • 314
  • 3
  • 14
  • on which environnement are you seeing this problem ? spring context aware unit test ? jboss deployement ? (Could that be a classloader problem : Are you for example using a jboss distribution that includes hibernate in servers/ctxt/lib and that the driver lib is in your war ?) – Thierry May 11 '10 at 15:53
  • Hi Thierry, I am trying to deploy the application in a local Jetty server for testing. Actually, is a little bit more complicated than that: Jetty is running inside a container of a Processing Unit(PU). So, the PU starts than it creates and starts the Jetty container. Jetty does the rest(WebAppContext is later registered with the PU). How can I track on which classloader my CustomJDBCDriver is beind loaded and the one that Spring is? Thanks! – Bill_BsB May 12 '10 at 09:21
  • Finally one of my colleagues at work found the solution for me. As @Thierry mentioned, it was a classloader problem. I was deploying my app with Spring libraries but the Processing Unit had those already loaded (lib folder of Jetty). So they were in conflict. The solution I found was to put my CustomJDBCDriver.jar in the same folder where the Spring jars are(jetty lib folder or from the apps /WEB-INF/lib), and make sure there is only one. That was it! Thanks all! – Bill_BsB May 13 '10 at 10:22

1 Answers1

1

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
  • 398,947
  • 96
  • 818
  • 769
  • 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 May 12 '10 at 08:57