Issue
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:
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: true
hibernate:
ddl-auto: update
naming-strategy: org.hibernate.cfg.EJB3NamingStrategy
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();
}
I used to create a custom namingStrategy extending ImplicitNamingStrategyJpaCompliantImpl
but nothing happened!
What is wrong?
What I want:
columns created in camel in the database. even tables!
Solution
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.
As you can see here: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html#common-application-properties
Answered By - Magd Kudama
Answer Checked By - Pedro (JavaFixing Volunteer)