Spring Boot JPA Insertion into Table with Uppercase Name Using Hibernate
Using Spring Boot JPA to insert records into a database, it is important to ensure the table name matches the entity name defined in the code. However, in some cases, the table name may be automatically converted to lowercase by default. This issue can arise when the table's name is declared in uppercase in the database, but the entity mapping in code uses a lowercase version.
To resolve this issue without modifying the MySQL configuration, it is necessary to adjust the Hibernate configuration in the Spring Boot application. By setting the following property in the application.properties file, you can specify the physical naming strategy for Hibernate 5:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
This naming strategy preserves the casing of the table name in the database, ensuring that the table name remains uppercase as defined. By making this adjustment, the insertion operations will correctly target the table with the uppercase name, resolving the issue of automatic conversion to lowercase.
The above is the detailed content of How to Preserve Table Name Casing with Spring Boot JPA and Hibernate?. For more information, please follow other related articles on the PHP Chinese website!