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

“hibernate时,对DialectResolutionInfo的访问不能为空。”。方言'未设置/多个数据库

傅新
2023-03-14

Spring启动应用程序。我有此数据源:

package _ourapp_.vTiger

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.jdbc.DataSourceBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.orm.jpa.JpaTransactionManager
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
import org.springframework.stereotype.Component
import javax.sql.DataSource

@Configuration
@Component("_ourapp_.vTiger")
@EnableJpaRepositories(
    basePackages = ["_ourapp_.vTiger"],
    entityManagerFactoryRef = "vTigerEntityManager",
    transactionManagerRef = "vTigerTransactionManager"
)
open class DataSource {

    @Bean
    @ConfigurationProperties(prefix = "database.vtiger")
    open fun calldata_base(): DataSource = DataSourceBuilder.create().build()

    @Bean
    open fun vTigerEntityManager(): LocalContainerEntityManagerFactoryBean =
        (LocalContainerEntityManagerFactoryBean()).apply {
            dataSource = calldata_base()
            setPackagesToScan("_ourapp_.vTiger.model")
            jpaVendorAdapter = HibernateJpaVendorAdapter()
        }

    @Bean
    open fun vTigerTransactionManager() = JpaTransactionManager(vTigerEntityManager().`object`!!)
}

和在应用程序属性:

database.vtiger.jdbc-url=jdbc:mariadb://_ourdatabaseinstance_.rds.amazonaws.com:3306
database.vtiger.user=_ourname_
database.vtiger.username=_ourname_
database.vtiger.password=_ourpass_
database.vtiger.maximum-pool-size=5
database.vtiger.driver-class-name=org.mariadb.jdbc.Driver
database.vtiger.database-platform=org.hibernate.dialect.MariaDBDialect
database.vtiger.dialect=org.hibernate.dialect.MariaDBDialect
hibernate.dialect=org.hibernate.dialect.MariaDBDialect

因为我们的应用程序有另一个数据库,为了简单起见这里省略了。

它正在连接到引擎版本 5.6.mysql_aurora.1.22.5 的 AWS Aurora 实例

应用程序启动失败,出现多条消息,包括

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vTigerEntityManager' defined in class path resource [au/com/ngv/kitten/vTiger/DataSource.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

(这就是为什么我引用了上面的特定来源,因为其中定义了vtigerEntityManager)但最后是可怕的

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

我之所以使用MariaDB,是因为IntelliJ数据库连接工具推荐它优于MySQL驱动程序。

明明hibernate.dialect设定的,怎么会‘不设定’application.properties?

如果相关的话,我在IntelliJ中使用了这个解决方法。当我在IntelliJ中运行应用程序时出现错误。

共有1个答案

壤驷经国
2023-03-14

这是要在application.properties中设置的正确变量:

spring.jpa.properties.hibernate.dialect 
 类似资料: