Access to dialectresolutioninfo cannot be null when hibernate.dialect not set oracle

하이버네이트

  • 자바 언어를 위한 객체 관계 매핑 프레임워크(ORM)으로,
    • 객체 지향 도메인 모델 -> 관계형 데이터베이스(RDB)로 매핑할때 쓰인다.
  • JPA의 구현체중 하나로, SQL을 직접사용하지 않고, 메서드 호출만으로 쿼리를 수행한다.
    • 내부적으로 SQL문이 돈다.

그런데, 굳이 하이버네이트를 공부하게된 이유가 무엇인가?

문제점 발견

애초에 하이버네이트를 쓸일은 데이터베이스와 접근할 때 쓰이게 되는데,
평소 Spring을 사용하면서 H2와 연동하다가, MySQL로 연동을 바꾸는 과정에서 문제가 발생하였다.

연동 DB 변경

  • Spring이 실행되면서 연동될 DB가 Mysql임을 설정해줘야하기에
    • datasource값에 mysql관련된 주소, 접근 할 수 있는 아이디 및 비밀번호
    • 그리고 지원하는 jdbc 드라이버를 설정값에 입력해줬다.
  • application.yml
spring: datasource: url: jdbc:mysql://localhost:3306/test username: shin password: **** driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: create # 스키마 자동 생성 show-sql: true # SQL 쿼리 출력 properties: hibernate: format_sql: true # SQL pretty print

오류발생

  • Access to DialectResolutionInfo cannot be null
    when 'hibernate.dialect' not set
  • 파파고의 힘을 빌려 해석해 보자면
    • 접근할 Dialect해결정보는 null일 수 없습니다.
    • 'hibernate.dialect'이 세팅되지 않았다.

dialect가 먼지 검색해보니까 , 사투리,방언으로 나온다.
맥락이 이상해지길래, 결국 하이버네이트의 dialect가 뭔지 찾아보게 되었다.

Hibernate. dialect

  • 하이버네이트가 데이터베이스와 통신을 하기 위해 사용하는 언어를 Dialect라고 한다.
  • 모든 데이터베이스에는 각자의 고유한 SQL언어가 있는데, 관계형 데이터베이스끼리 형태나 문법이 어느정도 비슷하긴 하지만, 완전히 똑같지는 않다.
    • 예를 들어 Oracle 쿼리 구문과 MySQL 쿼리구문은 다르다.
  • 하지만, 하이버네이트는 한 데이터베이스관리시스템(DBMS)에 국한되지않고, 다양한 DBMS에 사용 가능하다.
    • 내부적으로 각자 다른 페이징 방법을 처리해주고 있는 것이다.
    • 덕분에 특정 벤더(DBMS)에 종속적이지 않고, 얼마든지 대체가능하다.
  • JPA에서는 아래와 같이 Dialect라는 추상화된 언어 클래스를 제공하고 각 벤더에 맞는 구현체를 제공하고 있다.

Access to dialectresolutioninfo cannot be null when hibernate.dialect not set oracle

해결방안

  • 위 오류는 결국 MySql SQL를 처리해줄수 있는 dialect의 값이 제대로 설정되지 않아서 나타나는 오류임을 알수 있다.

  • 그래서 JPA에 값을 지정해주면 해결이 된다.

  • 해결한 application.yml

spring: datasource: url: jdbc:mysql://localhost:3306/test username: shin password: **** driver-class-name: com.mysql.cj.jdbc.Driver jpa: database: mysql # 추가 해준 부분 database-platform: org.hibernate.dialect.MySQL5InnoDBDialect # 추가 해준 부분 hibernate: ddl-auto: create show-sql: true properties: hibernate: format_sql: true
  • 만약 Oracle로 바꾸는 상황이었다면 OracleDiect를, H2로 바꾸는 상황이었다면 H2Dialect의 platform를 찾아 넣어주면된다.
  • 또한, 버전에 맞는 MySQL5InnoDBDialect dialect로 설정해줘야한다.
  • 보다, 많은 상황은 아래 링크를 참조하자.

참고자료

Hibernate 교육 해외사이트
버전에 맞는 설정

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final] at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final] ... 39 common frames omitted

오류는 위에 처럼 나온다.

postgreSQL를 사용하는 경우는 application.properties를 다음과 같이 수정한다.

... spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect spring.jpa.show-sql=false spring.jpa.hibernate.ddl-auto=create

낮은 버전의 Mysql 이나 MariaDB를 사용하는 경우는 다음을 추가한다.

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

stackoverflow.com/questions/26548505/org-hibernate-hibernateexception-access-to-dialectresolutioninfo-cannot-be-null

하지만, MySQL 4.x같은, 낮은 버전의 MySQL이나 mariaDB가 아닌 최신의 MySQL이나 mariaDB를 사용하는 경우,

다음의 링크를 확인하자.

team00csduck.tistory.com/entry/You-have-an-error-in-your-SQL-syntax-check-the-manual-that-corresponds-to-your-MySQL-server-version-for-the-right-syntax-to-use-near-typeMyISAM-%EC%98%A4%EB%A5%98-%EB%8C%80%EC%9D%91?category=827807

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use

Spring 기반 애플리케이션 가동 시에 mysql 4.x 버전이나 mariaDB의 낮은 버전과 최신 버전 사이의 문법 차이로 생기는 오류이다. 차이는 전자의 경우 type = MyISAM을 사용하지만, 후자(최신버전)의 경우 e

team00csduck.tistory.com

Access to dialectresolutioninfo cannot be null when hibernate.dialect not set oracle

'개발 > Spring' 카테고리의 다른 글

일반적인 Spring Security OAuth 인증의 High level flow  (0) 2021.02.13
Spring framework 계층구조  (0) 2021.02.08
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=MyISAM' 오류 대응  (0) 2021.01.27
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 오류 해결  (0) 2021.01.27
org.springframework.dao.DuplicateKeyException  (0) 2021.01.21
SpringBoot_framework_시작하기  (0) 2020.12.21

How do you resolve access to DialectResolutionInfo Cannot be null when Hibernate Dialect not set?

Fix for HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate. dialect' not set. After some research and debugging, I was able to fix it. The part that is missing in the official documentation is that we need to apply the configuration properties to StandardServiceRegistryBuilder .

What is hibernate dialect for Oracle?

Dialect allows Hibernate to generate SQL optimized for a particular relational database. Hibernate generates queries for the specific database based on the Dialect class. A hibernate dialect gives information to the framework of how to convert hibernate queries(HQL) into native SQL queries.

How do I get Hibernate Dialect?

SQL Dialects in Hibernate The dialect specifies the type of database used in hibernate so that hibernate generate appropriate type of SQL statements. For connecting any hibernate application with the database, it is required to provide the configuration of SQL dialect.

Is dialect mandatory in hibernate?

Note: The dialect property of hibernate is not mandatory.