Hibernate IntelliJ - Невозможно загрузить класс [org.postgresql.Driver] - PullRequest
0 голосов
/ 20 сентября 2018

Я хочу запустить свое собственное приложение Hibernate поверх базы данных psql, настроенной в intellij:

As you can see, I have the recent Postgresql Driver.

https://jdbc.postgresql.org/documentation/93/load.html неточно объясните, как должен быть настроен xml ...

Это ошибка, которую я получаю:

/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java --add-modules java.xml.bind "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50395:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Users/selfishound/Desktop/DBPRAK/3/Testat33/out/production/Testat33:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/hibernate-commons-annotations-5.0.1.Final.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/dom4j-1.6.1.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/classmate-1.3.0.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/jandex-2.0.3.Final.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/antlr-2.7.7.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/jboss-logging-3.3.1.Final.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/jboss-transaction-api_1.2_spec-1.0.1.Final.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/javassist-3.22.0-GA.jar:/Users/selfishound/Desktop/DBPRAK/3/Testat33/lib/hibernate-core-5.2.16.Final.jar Main
Sep 20, 2018 1:21:51 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.16.Final}
Sep 20, 2018 1:21:51 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 20, 2018 1:21:52 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Failed to create sessionFactory object.
Sep 20, 2018 1:21:55 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
    at SessionFactoryClass.<init>(SessionFactoryClass.java:15)
    at PersonRelatedImpl.<init>(PersonRelatedImpl.java:16)
    at Menu.<init>(Menu.java:9)
    at Main.main(Main.java:4)
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.postgresql.Driver]
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:348)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:163)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:119)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:103)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:75)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
    ... 17 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.postgresql.Driver
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:336)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:375)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:345)
    ... 29 more

Что я здесь не так делаю?Я попытался переименовать драйвер в org.postgresql.Driver.jar и переместить jar в корневой каталог, но это не помогло ... Возможно, это как-то связано с настройкой IntelliJ, но для меня это нормально: enter image description here

1 Ответ

0 голосов
/ 20 сентября 2018

Источник данных IDE никоим образом не связан с вашим приложением, включая способ настройки драйвера jdbc для него.Вам нужно добавить jar драйвера postgres jdbc к зависимостям вашего модуля .Обратите внимание, что если вы используете модули java 9, вам может потребоваться добавить его через файл информации модуля, см. Как использовать стороннюю библиотеку в модуле Java9? .

...