Home > Spring > ๐Ÿƒ[Spring] spring.jpa.properties.hibernate.dialect์ด๋ž€ ๋ฌด์—‡์ผ๊นŒ์š”?

๐Ÿƒ[Spring] spring.jpa.properties.hibernate.dialect์ด๋ž€ ๋ฌด์—‡์ผ๊นŒ์š”?
Spring Framework

๐Ÿƒ[Spring] spring.jpa.properties.hibernate.dialect์ด๋ž€ ๋ฌด์—‡์ผ๊นŒ์š”?

  • spring.jpa.properties.hibernate.dialect๋Š” Spring Boot ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ Hibernate๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” SQL(Structured Query Language) ๋ฐฉ์–ธ(dialect)์„ ์ง€์ •ํ•˜๋Š” ์„ค์ •์ž…๋‹ˆ๋‹ค.
  • Hibernate Dialect๋Š” Hibernate๊ฐ€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” SQL ๋ฐฉ์–ธ์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
    • ์ฆ‰, ์„œ๋กœ ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋งˆ๋‹ค ์‚ฌ์šฉํ•˜๋Š” SQL ๋ฌธ๋ฒ•์ด๋‚˜ ๊ธฐ๋Šฅ์ด ์•ฝ๊ฐ„์”ฉ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์—, Hibernate๊ฐ€ ๊ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ํŠน์„ฑ์— ๋งž๋Š” SQL์„ ์ƒ์„ฑํ•˜๋„๋ก ๋•๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.

1๏ธโƒฃ ์™œ ํ•„์š”ํ•œ๊ฐ€์š”?

  • ์„œ๋กœ ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” SQL(Structured Query Language) ๋ฌธ๋ฒ•์ด๋‚˜ ๊ธฐ๋Šฅ์ด ์กฐ๊ธˆ์”ฉ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
    • ์˜ˆ๋ฅผ ๋“ค์–ด, MySQL, Oracle, PostgreSQL, SQL Server ๋“ฑ์€ ์ผ๋ถ€ SQL ๋ฌธ๋ฒ•์ด๋‚˜ ํ•จ์ˆ˜์˜ ์ง€์› ๋ฐฉ์‹์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Hibernate๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋…๋ฆฝ์„ฑ์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋งž์ถฐ ๋™์ž‘ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
    • ๊ทธ๋Ÿฌ๋‚˜ ์ด๋ฅผ ์œ„ํ•ด ๊ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋งž๋Š” ์ ์ ˆํ•œ SQL(Structured Query Language)์„ ์ƒ์„ฑํ•ด์•ผ ํ•˜๋ฉฐ, ์ด๋ฅผ ์œ„ํ•ด Dialect๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • Hibernate Dialect๋Š” ํŠน์ • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋งž์ถฐ SQL ์ฟผ๋ฆฌ๋ฅผ ์ตœ์ ํ™”ํ•˜๊ฑฐ๋‚˜, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ํŠนํ™”๋œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

2๏ธโƒฃ ์„ค์ • ๋ฐฉ๋ฒ•.

  • Spring Boot์—์„œ spring.jpa.properties.hibernate.dialect๋ฅผ application.properties ๋˜๋Š” application.yml ํŒŒ์ผ์— ์„ค์ •ํ•˜์—ฌ, ์‚ฌ์šฉํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋งž๋Š” ๋ฐฉ์–ธ(dialect)์„ ๋ช…์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ‘‰ application.properties ํŒŒ์ผ์—์„œ ์„ค์ •.

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

๐Ÿ‘‰ application.yml ํŒŒ์ผ์—์„œ ์„ค์ •.

spring:
  jpa:
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQLDialect

3๏ธโƒฃ ๋Œ€ํ‘œ์ ์ธ Hibernate Dialect ์˜ˆ์‹œ.

1๏ธโƒฃ MySQL

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

2๏ธโƒฃ PostgreSQL

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

3๏ธโƒฃ Oracle

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect

4๏ธโƒฃ H2(In-Memory Database)

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect

5๏ธโƒฃ SQL Server

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect

4๏ธโƒฃ ์ž๋™ ์„ค์ •.

  • Spring Boot๋Š” ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ spring.datasource.url ์†์„ฑ์— ์„ค์ •๋œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค URL์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ ์ ˆํ•œ Hibernate Dialect๋ฅผ ์ž๋™์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
    • ๊ทธ๋ž˜์„œ ๋ณดํ†ต spring.jpa.properties.hibernate.dialect๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์„ค์ •ํ•  ํ•„์š”๋Š” ์—†์Šต๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜ ํŠน์ •ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฒ„์ „์— ๋งž๋Š” ํŠนํ™”๋œ ์ตœ์ ํ™” ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ์ž๋™ ์„ค์ •์ด ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์—๋Š” ์ด ์„ค์ •์„ ๋ช…์‹œ์ ์œผ๋กœ ์ •์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

5๏ธโƒฃ Hibernate Dialect์˜ ์—ญํ• .

1๏ธโƒฃ SQL ๋ฌธ๋ฒ• ์ตœ์ ํ™”.

  • ํŠน์ • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋งž๋Š” SQL ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
    • ์˜ˆ๋ฅผ ๋“ค์–ด, MySQL๊ณผ Oracle์—์„œ ์ž๋™ ์ฆ๊ฐ€ ํ•„๋“œ(autoincrement)๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์ด ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
      • Hibernate๋Š” ์ด ์ฐจ์ด์ ์„ Dialect๋ฅผ ํ†ตํ•ด ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

2๏ธโƒฃ ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋งคํ•‘.

  • ๊ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
    • Dialect๋Š” ์ž๋ฐ”์˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์ง€์›ํ•˜๋Š” ๋ฐ์ดํ„ฐํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

3๏ธโƒฃ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํŠนํ™” ๊ธฐ๋Šฅ.

  • ์ผ๋ถ€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” ํŠน์ • ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋ฉฐ, Dialect๋Š” ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ตœ์ ํ™”๋œ ์ฟผ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
    • ์˜ˆ๋ฅผ ๋“ค์–ด, PostgreSQL์˜ ์‹œํ€€์Šค๋‚˜ MySQL์˜ LIMIT ์ ˆ ๋“ค์ด ๊ทธ ์˜ˆ์ž…๋‹ˆ๋‹ค.

6๏ธโƒฃ ์š”์•ฝ.

  • spring.jpa.properties.hibernate.dialect๋Š” Hibernate๊ฐ€ ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐฉ์–ธ(Dialect)์„ ์ •์˜ํ•˜๋Š” ์„ค์ •์ž…๋‹ˆ๋‹ค.
  • ๊ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” SQL(Structured Query Language) ๋ฌธ๋ฒ•์ด๋‚˜ ๊ธฐ๋Šฅ์ด ์•ฝ๊ฐ„์”ฉ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์—, Hibernate๋Š” Dialect๋ฅผ ์‚ฌ์šฉํ•ด ํŠน์ • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋งž๋Š” SQL์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  • Spring Boot๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค URL์„ ํ†ตํ•ด ์ž๋™์œผ๋กœ ์ ์ ˆํ•œ Dialect๋ฅผ ์„ค์ •ํ•˜๋ ค๊ณ  ์‹œ๋„ํ•˜์ง€๋งŒ, ๋ช…์‹œ์ ์œผ๋กœ ์ด ์„ค์ •์„ ์ง€์ •ํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์ƒํ˜ธ์ž‘์šฉ์„ ์ตœ์ ํ™”ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.