Had*_*uli 4 hibernate spring-boot
JPA
我的 spring boot 项目在实体类中使用hibernate 注解。我有自己的通用存储库,并且我NOT
从 JPA 的entityManagerFactory 获取Hibernate SessionFactory。创建新表和列时会出现此问题。Camel 列在数据库上创建时带有下划线。我将命名策略更改为org.hibernate.cfg.EJB3NamingStrategy
inapplication.yml
但没有任何修复。
应用程序.yml:
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: true
hibernate:
ddl-auto: update
naming-strategy: org.hibernate.cfg.EJB3NamingStrategy
Run Code Online (Sandbox Code Playgroud)
在我自己的通用存储库中获取休眠会话(不使用EntityManager):
@Autowired
public SessionFactory sessionFactory;
public Session getSession() {
try {
return sessionFactory.getCurrentSession();
} catch (HibernateException e) {
System.out.println(e.getMessage().toString());
}
return sessionFactory.openSession();
}
Run Code Online (Sandbox Code Playgroud)
我曾经创建一个自定义的命名策略扩展,ImplicitNamingStrategyJpaCompliantImpl
但什么也没发生!
怎么了?
What I want:
在数据库中用骆驼创建的列。甚至桌子!
对于 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.
Run Code Online (Sandbox Code Playgroud)
正如您在这里看到的: https: //docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html#common-application-properties
归档时间: |
|
查看次数: |
19954 次 |
最近记录: |