栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

org.hibernate.HibernateException:如果未设置“hibernate.dialect”,则对DialectResolutionInfo的访问不能为null

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

org.hibernate.HibernateException:如果未设置“hibernate.dialect”,则对DialectResolutionInfo的访问不能为null

首先删除所有配置,Spring Boot将为您启动它。如果您确实需要a

SessionFactory
而不是
EntityManagerFactory
add
HibernateJpaSessionFactoryBean

确保您

application.properties
的类路径中有一个,并添加以下属性。

spring.datasource.driverClassName=org.postgresql.Driverspring.datasource.url=jdbc:postgresql://localhost:5432/teste?charSet=LATIN1spring.datasource.username=klebermospring.datasource.password=123spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialectspring.jpa.show-sql=falsespring.jpa.hibernate.ddl-auto=create

如果您确实需要访问,

SessionFactory
并且基本上是针对同一数据源的,则可以执行以下操作(尽管对于XML而不是JavaConfig,也可以在此处进行记录)。

@Configuration        public class HibernateConfig {    @Bean    public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {         HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();         factory.setEntityManagerFactory(emf);         return factory;    }}

这样,您就可以同时拥有

EntityManagerFactory
SessionFactory

假设您有一个带有

main
方法的类,
@EnableAutoConfiguration
则不需要
@EnableTransactionManagement
注释,因为Spring
Boot将为您启用该注释。
com.spring.app
包中的基本应用程序类应该足够了。

@Configuration@EnableAutoConfiguration@ComponentScanpublic class Application {    public static void main(String[] args) throws Exception {        SpringApplication.run(Application.class, args);    }}

这样的事情应该足以检测到您的所有类(包括实体和基于Spring Data的存储库)。

我还建议删除

commons-dbcp
依赖关系,因为这将允许Spring
Boot配置更快,更可靠的
HikariCP
实现。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/391722.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号