Home  >  Article  >  Java  >  Here are a few title options, emphasizing the question and problem: Short & Direct: * Why Are My Column Annotations Ignored in Spring Boot JPA? * Spring Boot JPA: Column Names Not Matching

Here are a few title options, emphasizing the question and problem: Short & Direct: * Why Are My Column Annotations Ignored in Spring Boot JPA? * Spring Boot JPA: Column Names Not Matching

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-28 05:34:30518browse

Here are a few title options, emphasizing the question and problem:

Short & Direct:

* Why Are My Column Annotations Ignored in Spring Boot   JPA? 
* Spring Boot   JPA: Column Names Not Matching Annotations - Why?

More Specific:

* Spring Boot   JPA: Un

Column Name Annotation Ignored in Spring Boot JPA

Problem:

Despite using column annotations in Spring Boot applications with data-jpa dependency, the generated SQL table column names differ from the annotations.

Cause:

This behavior is typically caused by the hibernate dialect used. In versions prior to Hibernate 5, Hibernate uses a default naming strategy that prefixes column names with an underscore. To override this strategy, you need to explicitly specify the naming strategy.

Solution:

For Hibernate 4:

Set the spring.jpa.hibernate.naming_strategy property to org.hibernate.cfg.EJB3NamingStrategy:

<code class="properties">spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy</code>

For Hibernate 5:

Add the following lines to your application.properties file:

<code class="properties">spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl</code>

By using these settings, Hibernate will adopt a naming strategy that respects the column annotations specified in your entities.

The above is the detailed content of Here are a few title options, emphasizing the question and problem: Short & Direct: * Why Are My Column Annotations Ignored in Spring Boot JPA? * Spring Boot JPA: Column Names Not Matching. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn