OSGI with Hibernate: “No suitable driver found”

爷,独闯天下 提交于 2019-12-13 19:01:26

问题


I'm getting the beloved error:

java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/acme

I understand many reasons why this error usually arises:

  • Invalid URL: This URL doesn't seem to have any errors in it and works perfectly fine in SQL Workbench.
  • Driver Not on ClassPath: It is successfully imported (org.postgresql.Driver) and can be instantiated either directly or by using Class.forName("org.postgresql.Driver").

The Hibernate SessionFactory loading is initiated from a Spring-Bean but is carried out at runtime with the following properties:

hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost:5432/acme
hibernate.connection.username = user
hibernate.connection.password = pass

I understand that the Java DriverManager does not work in OSGi, so registering the driver with the DriverManager or instantiating it to force it to register has no effect.

Does anyone know how I can fix this? Is there a common solution?

Thanks in advance!


The Solution

As pointed out by Andres Olarte, I made a mistake of adding the driver to the implementation bundle, but leaving it out of the Hibernate bundle where Hibernate's classes and dependencies reside.


回答1:


How do you have this packaged? If you put the Hibernate and the Postgresql JDBC jar in the same OSGi bundle, it should work. This is what BIRT does load its jdbc drivers.



来源:https://stackoverflow.com/questions/8013205/osgi-with-hibernate-no-suitable-driver-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!