hibernate - 改变Hibernate 5命名策略+spring boot+注解

标签 hibernate spring-boot

我的 Spring Boot 项目在实体类中使用 JPA hibernate 注解。我有自己的通用存储库,我 NOT 从 JPA 的 entityManagerFactory 获取 Hibernate SessionFactory。创建新表和列时会出现此问题。 Camel 列是在数据库中使用下划线创建的。 我在 application.yml 中将命名策略更改为 org.hibernate.cfg.EJB3NamingStrategy 但没有修复。

application.yml:

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

在我自己的通用存储库中获取 hibernate session (不使用 EntityManager):

@Autowired
public SessionFactory   sessionFactory;

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

我曾经创建一个自定义命名策略扩展 ImplicitNamingStrategyJpaCompliantImpl 但什么也没发生!

怎么了?

我想要什么:

在数据库中以 Camel 方式创建的列。甚至是 table !

最佳答案

使用 Hibernate 5,您应该使用不同的属性:

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 - 改变Hibernate 5命名策略+spring boot+注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41918622/

相关文章:

spring-boot - 如何使用 spring data cassandra 创建一组用户定义类型?

mysql - hibernate中使用单表策略时将父类(super class)的实例更新为子类的实例

Spring Boot JPA Like 查询

java - 包 org.hibernate 可以从多个模块访问 : hibernate. commons.annotations, hibernate.core

java - 如何使用 hibernate JPA 注释连接两列

java - 有什么方法可以继承不是@MappedSuperclass 的实体?

spring - 如何使用带有 SSL 的 Spring WebSocketClient?

java - 无法从唯一字段的外键表中获取数据

java - ArrayList 不能使用 Texo 生成的模型设置为 hibernate 状态

spring-boot - 在 Spring Boot 中通过代理将 HTTP 直接转换为 HTTPS