J
J
Jake Taylor2021-10-31 16:31:43
Hibernate
Jake Taylor, 2021-10-31 16:31:43

Why does the given Naming Strategy in Spring Boot not work?

I use Spring Boot + Hibernate.
In application.propertiesindicated to use PhysicalNamingStrategy:

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

This strategy means:
- all dots are replaced with underscores
- camelCase is also replaced with underscores
- by default all table names are in lower case. For example, the TelephoneNumber object maps to the phone_number table.

There is an entity Java class named GiftCertificate. But for some reason, when the request is executed, the name of this class is not converted to gift_certificate, as expected by me, but to giftcertificate, which can be seen from the logs:
java.sql.SQLSyntaxErrorException: Table 'gift_certificates_system_db.giftcertificate' doesn't exist


Why is this happening and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jake Taylor, 2021-10-31
@n199a

ImplicitNamingStrategyused when the database name, table name, column name is not explicitly specified in the entity definition. Those. when the @Table annotation is not used, or when the @Column annotation is present but the name property is not set.
PhysicalNamingStrategythe strategy comes into play when the database name, table name, column name is explicitly set, for example @Column(name = "camelCase"). That's when Hibernate will already work with the value of the name parameter.
Properties are set in application.properties:

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

I needed a strategy ImplicitNamingStrategy, not a PhysicalNamingStrategy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question