Search code examples
javaspring-boothibernatejpanaming-strategy

PhysicalNamingStrategyStandardImpl JPA hibernate naming works for dev/local but not in testing


My table name is in camelcase and the hibernate (v5) naming is PhysicalNamingStrategyStandardImpl which works when running the application using @SpringBootApplication but when it is used in testing and using @DataJpaTest it turns the camelcase name to all uppercase and so the test will not get executed.

I have also made sure that I have two separate application.yml one for dev and one for testing and the one for testing works

This is how I declared my naming which worked for dev/local:

jpa:
  hibernate:
    naming:
      physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

The table name is declare as following: @Table(name = "ClinicalUser") Getting the following error:

ERROR 35284 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : Table "CLINICALUSER" not found

I like to mention again that this worked when used on dev/local env.

I have checked all the other related questions and they either couldn't connect to their test application.yml or they had different problems with different naming.


Solution

  • I dont really understand what was exactly wrong but I had the h2 dependency on my pom.xml file and after removing that and adding @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) under the @DataJpaTest it worked.