4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Java][Spring Boot][MySQL] テーブル名/列名等の大文字小文字を区別する方法 - NetBeansで始めるSpring Boot (9)

Posted at

環境

  • Spring Boot 1.4.2
  • Java 8

概要

例えば、以下のようにエンティティのテーブル名を大文字にしていても、データベースには小文字でアクセスするようになっています。

@Entity
@Table("MY_ENTITY")
class MyEntity {
  // ...
}

これを、大文字でアクセスするようにする方法です。

詳細

Spring Bootのデフォルトでは、物理名マッピングするためのクラスが設定されています

物理名マッピングは、SpringPhysicalNamingStrategyクラスで行われています。

上記クラスの中ですべて小文字変換しているので、大文字小文字を区別するMySQLでは困ってしまいます。

解決策

apprication.ymlまたは同propertiesの中で、物理名マッピングするクラスをHibernateオリジナルのものに変更します。

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

真の解決策

テーブル名/列名は小文字にするのが安心安全です。 :smile:

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?