강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

yootdh님의 프로필 이미지
yootdh

작성한 질문수

java.lang.NullPointerException

작성

·

1.2K

0

java.lang.NullPointerException: Cannot invoke "org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(java.sql.SQLException, String)" because the return value of "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.sqlExceptionHelper()" is null

이러한 문제가 뜨는데 뭐가 문제일까요?

현재 mariaDB를 쓰고 있구요 docker를 사용해서mariaDB를 실행 시킨 상태인데요

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>3.3.1</version>
   <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.example</groupId>
  <artifactId>ex2</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>ex2</name>
  <description>Demo project for Spring Boot</description>
  <url/>
  <licenses>
   <license/>
  </licenses>
  <developers>
   <developer/>
  </developers>
  <scm>
   <connection/>
   <developerConnection/>
   <tag/>
   <url/>
  </scm>
  <properties>
   <java.version>17</java.version>
  </properties>
  <dependencies>
   <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
   </dependency>
   <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
   </dependency>
   <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
   </dependency>

   <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
   </dependency>
   <dependency>
    <groupId>org.mariadb.jdbc</groupId>
    <artifactId>mariadb-java-client</artifactId>
    <scope>runtime</scope>
   </dependency>
   <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
   </dependency>
   <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
   </dependency>
  </dependencies>

  <build>
   <plugins>
    <plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
      <excludes>
       <exclude>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
       </exclude>
      </excludes>
     </configuration>
    </plugin>
   </plugins>
  </build>

</project>

이건 현재 저의 pom.xml이고

# App name
spring.application.name=ex2

# Server port
server.port=8080

# Context path
server.servlet.context-path=/ex2

# Restart WAS
spring.devtools.livereload.enabled=true

# Spring Datasource
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=jdbc:mariadb://localhost:3309/db7
spring.datasource.username=db7
spring.datasource.password=1234

# JPA
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=true

이건 현재 저의 application.properties입니다.

package com.example.ex2.repository;

import com.example.ex2.entity.Memo;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemoRepsitory extends JpaRepository<Memo, Long> {

}


이게 MemoRepository구요

package com.example.ex2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Ex2Application {

  public static void main(String[] args) {
   SpringApplication.run(Ex2Application.class, args);
  }

}


이건 Ex2Application입니다.
그리고 오류가 이것 뿐만이 아닌

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)

 

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)

 

Caused by: org.hibernate.HibernateException: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)

 

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@675ec28b testClass = com.example.ex2.repository.MemoRepsitoryTests, locations = [], classes = [com.example.ex2.Ex2Application], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@e15b7e8, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@43dac38f, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@1de5f259, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@506ae4d4, org.springframework.boot.test.context.SpringBootTestAnnotation@fe3b3617], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]


Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)

 

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)

 

 

Caused by: org.hibernate.HibernateException: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)

 

이런 오류들이 뜹니다.... 뭐가 문제인지를 모르겠어요

답변 1

0

안녕하세요, 인프런 AI 인턴입니다.

yootdh님, 설명해주신 내용을 바탕으로 보았을 때 주요 문제는 Hibernate 설정에서 발생하는 것으로 보입니다. 오류 메시지에 따르면, Hibernate가 JDBC 메타데이터를 기반으로 dialect를 결정할 수 없기 때문에 문제가 발생하는 것 같습니다. application.properties 파일에 명시적으로 hibernate dialect를 설정해 주어야 할 필요가 있어 보입니다. MariaDB를 사용하고 계시므로 MariaDB에 맞는 Dialect를 설정해보시기를 추천드립니다.

application.properties에 다음과 같은 설정을 추가해보세요:

# Hibernate Dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect

이 설정은 Hibernate에게 MariaDB를 사용하고 있으며 해당 데이터베이스에 최적화된 SQL 문을 생성하도록 지시합니다.

또한, JDBC URL을 jakarta.persistence.jdbc.url 대신 spring.datasource.url에 정의하신 것처럼 올바르게 설정하셨는지 확인해보세요. 이미 spring.datasource.url을 통해 올바르게 설정하신 것 같으니, 이 부분은 문제가 없어 보입니다.

만약 설정 후에도 문제가 계속된다면, MariaDB 서버가 올바르게 실행되고 있는지, docker를 통해 MariaDB를 실행할 때 사용한 포트와 application.properties에서 지정한 포트(3309)가 일치하는지 확인해 주세요.

이 정보가 yootdh님의 문제 해결에 도움이 되었기를 바랍니다.

yootdh님의 프로필 이미지
yootdh

작성한 질문수

질문하기