本文介绍了带有Hibernate的OSGI:“找不到合适的驱动程序”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
java.sql.SQLException:找不到合适的jdbc驱动程序:postgresql: // localhost:5432 / acme
我明白为什么会出现这种错误的原因很多:
- 无效的网址:该网址似乎没有任何错误,并且在SQL Workbench中完美无缺。 li>
- 驱动程序不在ClassPath上:成功导入(org.postgresql.Driver),可以直接实例化或使用Class.forName(org.postgresql。 )。
Hibernate SessionFactory
Bean,但在运行时使用以下属性执行:
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql:// localhost:5432 / acme
hiberna te.connection.username = user
hibernate.connection.password = pass
据我所知Java DriverManager
在OSGi中不起作用,所以向 DriverManager
注册驱动程序或者实例化它以强制它注册没有任何效果。
有谁知道我该如何解决这个问题?有没有共同的解决方案?
预先感谢!
解决方案
正如Andres Olarte所指出的那样,我将错误的驱动添加到实现包,但将它从Hibernate的类和依赖关系所在的 Hibernate bundle 之外。
你有这个包装吗?如果您将Hibernate和Postgresql JDBC jar放在同一个OSGi包中,它应该可以工作。这是BIRT加载其jdbc驱动程序的功能。
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.
解决方案
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.
这篇关于带有Hibernate的OSGI:“找不到合适的驱动程序”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!