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