我收到此错误。也尝试了两个jar文件到src文件夹,项目文件夹等。请检查并提供帮助。
在不同的项目中都尝试了Hibernate 3.6.4和5.4.2。
CITY_CENSUS.groupBy("city").agg(count("population"))
我的休眠配置文件如下:
294 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.4.Final
297 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
303 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
311 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
446 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
446 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
1330 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
1476 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: org.SecondHibernateProject.dto.UserDetails
1550 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity org.SecondHibernateProject.dto.UserDetails on table UserDetails
1629 [main] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
1635 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
1647 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1647 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
1647 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
1678 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.postgresql.Driver at URL: jdbc:pstgresql://localhost:5432/hibernatedb
1678 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=admin, password=****}
1680 [main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
java.sql.SQLException: No suitable driver found for jdbc:pstgresql://localhost:5432/hibernatedb
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
at org.vishal.hibernate.HibernateTest2.main(HibernateTest2.java:12)
1742 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.PostgreSQLDialect
1760 [main] INFO org.hibernate.engine.jdbc.JdbcSupportLoader - Disabling contextual LOB creation as connection was null
1762 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
1764 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
1764 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
1764 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
1765 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: disabled
1765 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
1765 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
1766 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
1767 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
1767 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
1767 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
1767 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
1770 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
1771 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
1771 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
1772 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
1772 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
1773 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
1777 [main] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.NoCacheProvider
1778 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
1778 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
1784 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
1785 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
1785 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
1786 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
1786 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
1786 [main] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled
1868 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
1882 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@35fc6dc4
2572 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
2584 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
2585 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
2585 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - schema export unsuccessful
java.sql.SQLException: No suitable driver found for jdbc:pstgresql://localhost:5432/hibernatedb
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:263)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:219)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:372)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
at org.vishal.hibernate.HibernateTest2.main(HibernateTest2.java:12)
2659 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 08001
2659 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No suitable driver found for jdbc:pstgresql://localhost:5432/hibernatedb
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
at org.vishal.hibernate.HibernateTest2.main(HibernateTest2.java:14)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:pstgresql://localhost:5432/hibernatedb
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 5 more
主Java类如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database Connection Settings
-->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:pstgresql://localhost:5432/hibernatedb</property>
<property name="connection.username">admin</property>
<property name="connection.password">admin</property>
<!-- JDBC Connection pool (use the build-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Disable Second level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Names the annotated entity class -->
<mapping class="org.SecondHibernateProject.dto.UserDetails" />
</session-factory>
</hibernate-configuration>
答案 0 :(得分:0)
可以请参考给定的步骤来解决此问题。
根据版本从给定路径下载PostgreSQL jar。 https://jdbc.postgresql.org/download.html
使用Eclipse中的“外部jar”选项将jar添加到项目中。
确保将“ hibernate.cfg.xml”文件放置在“ src”的根目录下 文件夹(如果您使用给定的代码读取此文件)。
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
如果“ hibernate.cfg.xml”位于其他位置,则从给定路径读取此文件。
SessionFactory sessionFactory = new Configuration().configure("/path/to/hibernate.cfg.xml").buildSessionFactory();