gpt4 book ai didi

java - 当 'hibernate.dialect' 未使用 spring-boot 设置时,对 DialectResolutionInfo 的访问不能为 null

转载 作者:搜寻专家 更新时间:2023-11-01 02:19:32 28 4
gpt4 key购买 nike

我正在尝试在我的 spring-boot 项目中配置 hibernate 。

我有 application.properties 文件

spring.datasource.url=jdbc:mysql:url?useSSL=false
spring.datasource.username=name
spring.datasource.password=password

hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql:url
hibernate.connection.username = name
hibernate.connection.password = password
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect=org.hibernate.dialect.MySQLDialect

以及在 UserDAO 类中注册用户的方法:

public void registerUser(User u){
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.save(u);
tx.commit();
} catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
System.out.println("yay all done");
}

但是我收到错误:

> Caused by: 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:275)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:179)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:119)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:84)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:474)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> com.groups.data.UserDAO.<init>(UserDAO.java:18) ~[classes/:na] ... 52
> common frames omitted Caused by: org.hibernate.HibernateException:
> Access to DialectResolutionInfo cannot be null when
> 'hibernate.dialect' not set at
> org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final] ... 66 common frames
> omitted

我已经根据需要配置了方言,我什至尝试创建良好的旧 hibernate.cfg.xml 文件,但错误仍然存​​在(它甚至似乎忽略了该文件)。

为什么会发生这种情况?从字面上看,昨天它没有问题。今天我尝试创建 cfg 文件,但它停止工作(已将其删除)。

我尝试配置 hibernate 的次数越多,它似乎越是激怒任何使用它的人并且不可能让它工作。

这可能是什么问题?

感谢您的帮助!

最佳答案

您是否已将此行添加到您的 application.properties 文件中?

spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

DB2
org.hibernate.dialect.DB2Dialect

DB2 AS/400
org.hibernate.dialect.DB2400Dialect

DB2 OS390
org.hibernate.dialect.DB2390Dialect

PostgreSQL
org.hibernate.dialect.PostgreSQLDialect

MySQL
org.hibernate.dialect.MySQLDialect

MySQL with InnoDB
org.hibernate.dialect.MySQLInnoDBDialect

MySQL with MyISAM
org.hibernate.dialect.MySQLMyISAMDialect

Oracle (any version)
org.hibernate.dialect.OracleDialect

Oracle 9i/10g
org.hibernate.dialect.Oracle9Dialect

Sybase
org.hibernate.dialect.SybaseDialect

Sybase Anywhere
org.hibernate.dialect.SybaseAnywhereDialect

Microsoft SQL Server
org.hibernate.dialect.SQLServerDialect

SAP DB
org.hibernate.dialect.SAPDBDialect

Informix
org.hibernate.dialect.InformixDialect

HypersonicSQL
org.hibernate.dialect.HSQLDialect

Ingres
org.hibernate.dialect.IngresDialect

Progress
org.hibernate.dialect.ProgressDialect

Mckoi SQL
org.hibernate.dialect.MckoiDialect

Interbase
org.hibernate.dialect.InterbaseDialect

Pointbase
org.hibernate.dialect.PointbaseDialect

FrontBase
org.hibernate.dialect.FrontbaseDialect

Firebird
org.hibernate.dialect.FirebirdDialect

关于java - 当 'hibernate.dialect' 未使用 spring-boot 设置时,对 DialectResolutionInfo 的访问不能为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51847358/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com