gpt4 book ai didi

java - Spring实体管理器无法启动: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

转载 作者:行者123 更新时间:2023-12-02 09:20:45 30 4
gpt4 key购买 nike

作为开发人员我想开发一个 Spring JPA 来访问 Oracle 9i 数据库以通过存储过程获取记录我想通过 application.yml 连接到数据库,但我使用配置文件 application.properties 启动项目

我在 application.properties 中声明了这一点

    spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.dialect=org.hibernate.dialect.Oracle9iDialect
spring.jpa.database=default
spring.main.allow-bean-definition-overriding=true
spring.datasource.driverClassName=oracle.jdbc.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle9iDialect

以及 application.yml

 jpa:
hibernate:
ddl-auto: none

naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
properties:
hibernate:
proc.param_null_passing: true
dialect: org.hibernate.dialect.Oracle9iDialect
show-sql: true

执行时,会引发以下异常

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

您能告诉我还有什么其他方法可以修改类或配置文件吗?这是我的配置类代码:

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
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.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.Properties;

@Configuration
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class})
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "productEntityManagerFactory",
transactionManagerRef = "productTransactionManager",
basePackages = {"com.pccw.ruby.repository"})

public class DBConfiguration {

@Primary
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}

@Primary
@Bean
LocalContainerEntityManagerFactoryBean entityManagerFactory() {

HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(false);
vendorAdapter.setShowSql(true);

LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(dataSource());
factoryBean.setJpaVendorAdapter(vendorAdapter);
factoryBean.setPackagesToScan("com.pccw.ruby.domain");

Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.proc.param_null_passing", new Boolean(true));
jpaProperties.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName());
jpaProperties.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class.getName());
factoryBean.setJpaProperties(jpaProperties);

return factoryBean;
}

@Primary
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}

这是我的 Oracle 数据库版本:

Oracle9i 企业版版本 9.2.0.6.0 - 64 位生产

最佳答案

    Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.proc.param_null_passing", new Boolean(true));
jpaProperties.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName());
jpaProperties.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class.getName());
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.Oracle9iDialect");

尝试在这里设置。

关于java - Spring实体管理器无法启动: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58708683/

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