当前位置: 首页 > 知识库问答 >
问题:

访问方言分辨率Info不能为空,当“Hibernate方言”未使用Spring启动设置时

云星波
2023-03-14

我正在尝试在我的Spring引导项目中配置hibernate。

我有申请。属性文件

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

我已经按照它的要求配置了方言,我甚至尝试过创建一个好的旧的< code>hibernate.cfg.xml文件,但是错误还是一样(它甚至好像忽略了这个文件)。

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

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

这里会有什么问题?

感谢您的帮助!

共有1个答案

爱刚捷
2023-03-14

是否已将此行添加到应用程序属性文件中?

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

DB2
org.hibernate.dialect.DB2Dialect

DB2 AS/400 < br > < code > org . hibernate . dialect . db 2400 dialect

DB2 OS390
组织.Hibernate.dialect.DB2390方言

PostgreSQL
org.hibernate.dialect.PostgreSQL方言

MySQL
org.Hibernate.dialect.MySQL方言

MySQL与InnoDB < br > < code > org . hibernate . dialect . MySQL InnoDB dialect

MySQL with MyISAM < br > < code > org . hibernate . dialect . mysqlmyisamdialect

Oracle(任何版本)
org.hibernate.dialect.OracleDialect

Oracle 9i/10g
org.hibernate.dialect.Oracle9方言

Sybase
org.Hibernate.dialect.Sybase方言

Sybase Anywhere
org.hibernate.dialect.SybaseAnywhreeDialect

微软SQL服务器
org.hibernate.dialect.SQLServerDialect

SAP DB
org.hibernate.dialect.SAPDBDialect

Informix
org.hibernate.dialect.Informix方言

高超音速SQL
组织.Hibernate.dialect.HSQL方言

Ingres
org.hibernate.dialect.IngresDialect

进步
组织.Hibernate.方言.进步方言

Mckoi SQL
org.hibernate.dialect.MckoiDialect

基间
组织.Hibernate.方言.跨基地方言

point base < br > < code > org . hibernate . dialect . pointbase dialect

FrontBase
org.hibernate.dialect.FrontbaseDialect

firebird < br > < code > org . hibernate . dialect . firebird dialect

 类似资料: