更改Hibernate 5命名策略+ Spring Boot +注释 [英] change Hibernate 5 naming strategy + spring boot + annotation

查看:278
本文介绍了更改Hibernate 5命名策略+ Spring Boot +注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的spring boot项目在实体类中使用JPA hibernate注释.我有自己的通用存储库,并且NOT从JPA的entityManagerFactory获取Hibernate SessionFactory.当创建新的表和列时,会发生此问题.在数据库上创建带有下划线的驼峰列. 我在application.yml中将命名策略更改为org.hibernate.cfg.EJB3NamingStrategy,但是没有固定的内容.

My spring boot project is using JPA hibernate annotation in entity classes. I have my own generic repository and I'm NOT getting the Hibernate SessionFactory from JPA's entityManagerFactory. The problem occurs when new tables and columns are created. Camel columns are created with an underscore on the database. I changed the naming strategy to org.hibernate.cfg.EJB3NamingStrategy in application.yml but nothing fixed.

application.yml:

application.yml:

 jpa:
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect 
    show-sql: true 
    hibernate:
        ddl-auto: update 
        naming-strategy: org.hibernate.cfg.EJB3NamingStrategy

在我自己的通用存储库中获取休眠会话(不使用EntityManager):

Getting hibernate session in My own Generic repository (not using EntityManager):

@Autowired
public SessionFactory   sessionFactory;

public Session getSession() {
    try {
        return sessionFactory.getCurrentSession();
    } catch (HibernateException e) {
        System.out.println(e.getMessage().toString());
    }
    return sessionFactory.openSession();
}

我曾经创建一个自定义的namingStrategy扩展ImplicitNamingStrategyJpaCompliantImpl,但是什么也没发生!

I used to create a custom namingStrategy extending ImplicitNamingStrategyJpaCompliantImpl but nothing happened!

怎么了?

What I want:

列.甚至桌子!

推荐答案

对于Hibernate 5,您应该使用其他属性:

With Hibernate 5, you should be using different properties:

spring.jpa.hibernate.naming.implicit-strategy= # Hibernate 5 implicit naming strategy fully qualified name.
spring.jpa.hibernate.naming.physical-strategy= # Hibernate 5 physical naming strategy fully qualified name.

您可以在此处看到: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html#common-application-properties

这篇关于更改Hibernate 5命名策略+ Spring Boot +注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆