0

I created an entityFactoryManager bean since I am doing @EnableAutoConfiguration(exclude = HibernateJpaAutoConfiguration.class). When running the application, I got an error and found that a naming strategy changed from snake_case to camel case. In my case, my property userDetail because table name userdetail instead of user_detail. I tried setting hibernate property hibernate.implicit_naming_strategy to jpa or default and it doesn't work. I tried physical implementation provided, and no luck. I would think I shouldn't have to change any hibernate properties since it would just be using default settings, assuming auto configuration does that.

I must be missing something here.

hibernate 5.4 spring 2.3

SternK
  • 11,649
  • 22
  • 32
  • 46
Gentouru
  • 1
  • 2
  • Maybe this [answer](https://stackoverflow.com/a/58849104/7598851) could help you to customize used naming strategy. – MartinBG Sep 12 '20 at 08:03
  • I believe customize will work but i do not need to do that since default will work as long as I do not implement my own entityFactoryManager. I don't understand why when I deploy my own entityFactoryManager, the naming strategy changed to camel. – Gentouru Sep 13 '20 at 02:14

1 Answers1

0

The problem was caused by a combination of hibernate property name and the value that was set.

If you implement your own entity factory, hibernate properties are set to a default settings that doesn't seem to match hibernate's user guide such as the problem I am facing and it seems to be the only one.

Since I am using @EnableAutoConfiguration(exclude = {HibernateJpaAutoConfiguration.class }), the application.properties for hibernate setup doesn't apply anymore. Below is not necessary since by default via auto configuration, it is snake case. Solution below is also mentioned by many people to get it to work with snake case.

spring.jpa.hibernate.naming.implicit-strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicityNamingStrategy spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

Noticed that "hibernate.naming.physical-strategy" is the property name to set but that is not the case when you set it within your property class, you have to set your hibernate property to 'hibernate.physical-strategy'

Another problem is the property value. I went from hibernate's doc..

Implicit: default, jpa, org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl Physical: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

to this..

Implicit: org.springframework.boot.orm.jpa.hibernate.SpringImplicityNamingStrategy Physical: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

I have a feeling that hibernate's implementation is probably different than jpa's. It doesn't matter what value i set using hibernate's, it does not work. Setting the SpringPhysicalNamingStrategy fixed the problem. SpringImplicityNamingStrategy doesn't do anything as well.

Another issue I am having is that lazy loading doesn't behave the same but hibernate.enable_lazy_load_no_trans is an anti-pattern workaround.

Gentouru
  • 1
  • 2