🟦 기본 환경: IDE: IntelliJ, Language: Java

 

 

발생 Error

SpringBoot에서 SpringBoot 3.x대 project import 시, 🚨 다음과 같은 Error 발생

A problem occurred configuring root project 'NewProject'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.0.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.0
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.0 was found.
  The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally,
  as well as attribute 'org.gradle.plugin.api-version' with value '7.6.1' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11

 

 

발생 원인

SpringBoot 3.0 부터는 Java 17부터 지원

 

 

해결 방법

1. SpringBoot를 2.x대로 다운그레이드

2. Java17 설치

  2.1. File / Settings / Build, Execution, Deployment / Build Tools / Gradle 

  : Gradle JVM: Java17 이상으로 설정

  2.2. File / Project Structure / Project

  : SDK - Java 17 이상으로 설정

  : Language level - SDK default로 설정

  2.3. File / Project Structure / Modules

  : Language level - project default로 설정

  2.4. Gradle Refresh

 

 

 

참고 자료

 

Spring Boot 3.x 실행이 안될 경우 (feat. IntelliJ)

스프링 부트 3.0 이 출시되었다. (현재 최신은 3.0.1 이지만) 3.0 부터는 Java 17부터 지원된다. 그러다보니 기존에 Java8, 11등을 사용하시던 분들은 3.x 스프링 부트 프로젝트를 실행할때 에러들을 만나

jojoldu.tistory.com

 

🟦 기본 환경: IDE: IntelliJ, Language: Java

 

 

발생 Error

SpringBoot에서 다음 Source Code를 실행할 경우,

검색 버튼 클릭 시, 🚨다음과 같은 Error 발생

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: . near line 1, column 67 [select o from jpabook.jpashop.domain.Order o join o.member mwhereo.status = :statusandm.name like :name]; 

nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: . near line 1, column 67 [select o from jpabook.jpashop.domain.Order o join o.member mwhereo.status = :statusandm.name like :name]

 

 

발생 원인

jpql 작성 시, ' ' 띄어쓰기 부재로 인한 구문의 부정확한 인식

 

해결 방법

관련 Controller에 action 주소 @PostMapping 메서드 추가

9행, 12행, 14행에서 구문 앞에 ' ' 띄어쓰기 추가

❌ Query문 작성 시, 띄어쓰기 유의

 

이 글은 김영한의 [실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발] 수강하며 정리한 글입니다.

 

 

🟦 기본 환경: IDE: IntelliJ, Language: Java

 

 

1. Dirty Checking, 변경감지

: Transaction Commit 시, 영속화된 Entity에서 가지고 있던 최초의 정보(Snap Shot)와 바뀐 Entity 정보를 비교해서 변경된 부분을 update해주는 기능

@Transaction 안에서 entity 값을 변경해야 dirty checking, 변경 감지가 일어날 수 있음
: flush  commit update query → DB

 

 

2. Merge, 병합

: 준영속 상태의 엔티티를 영속 상태로 변경할 때 사용

준영속 엔티티의 식별자 값으로 영속 엔티티를 조회(1차 캐시/DB→1차 캐시)
 → 영속 엔티티의 값을 준영속 엔티티의 값으로 모두* 교체
 → 트랜잭션 커밋 시점에 변경 감지 기능을 통해 데이터베이스에 UPDATE SQL 실행

* 모든 값이 변경되므로 입력되지 않은 값은 null로 변경되는 위험 존재

 

 

 

+ Entity 생명 주기

+ 영속성 컨텍스트

: 엔티티를 영구 저장하는 환경, 애플리케이션과 데이터베이스 사이에서 객체를 보관하는 가상의 데이터베이스 같은 역할

 : 엔티티 매니저를 통해 엔티티를 저장하거나 조회하면 엔티티 매니저는 영속성 컨텍스트에 엔티티를 보관하고 관리
 : 엔티티 매니저를 생성할 때 하나 만들어지며, 엔티티 매니저를 통해서 접근하고 관리할 수 있음

 

 

 

참고 자료

 

[JPA] 변경감지 개념과 @Transactional 위치에 따른 변경감지 사용

데이터 변경 로직에서 JPA 변경감지 기능을 자주 접할 수 있는데요. JPA 변경감지에 대해서 짤막한 정리와 함께 @Transactional과 같이 사용할 때 어떠한 점을 유의해야 되는지에 대해서 정리해보고자

beaniejoy.tistory.com

 

[JPA] 영속성 컨텍스트와 플러시 이해하기

영속성 컨텍스트JPA를 공부할 때 가장 중요한게객체와 관계형 데이터베이스를 매핑하는 것(Object Relational Mapping) 과영속성 컨텍스트를 이해하는 것 이다. 두가지 개념은 꼭 알고 JPA를 활용하자.

ict-nroo.tistory.com

 

 

[JPA] 변경 감지와 병합(merge)

지난번에 진행했던 hello shop 프로젝트에서 상품 수정 시 사용됐던 merge() 라는 친구를 기억하나 혹시~😎? JPA에서 준영속 엔티티를 수정하는 방법에는 2가지가 있는데, 이것이 매우 중요하다고 강

velog.io

 

'Java > JPA' 카테고리의 다른 글

[SpringBoot_JPA_1] @NoArgsConstructor  (1) 2023.05.30
[SpringBoot_JPA_1] @Transactional  (0) 2023.05.29
[SpringBoot_JPA_1] StringUtils.hasText()  (0) 2023.05.27
[SpringBoot_JPA_1] create Private Method  (0) 2023.05.27
[SpringBoot_JPA_1] Injection  (0) 2023.05.25

🟦 기본 환경: IDE: IntelliJ, Language: Java

 

 

발생 Error

SpringBoot에서 다음 Source Code를 실행할 경우,

Submit 버튼 클릭 시, 🚨다음과 같은 Error 발생

Request method 'POST' not supported
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:260)

 

 

발생 원인

button 클릭에 따른 submit action이 취해지는 곳에서 POST방식으로 데이터를 전송하지만 해당 URL을 처리하는 Controller에서 처리되지 않음

+ action이 없는 경우, 폼은 현재 페이지의 URL을 대상으로 데이터를 제출

 

 

해결 방법

관련 Controller에 action 주소 @PostMapping 메서드 추가

 

🟦 기본 환경: IDE: IntelliJ, Language: Java

 

 

발생 Error

SpringBoot에서 다음 Source Code를 실행할 경우,

이름을 입력하지 않고 submit 버튼 클릭 시, 🚨다음과 같은 Error 발생

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'memberForm' on field 'name': rejected value [];

codes [NotEmpty.memberForm.name,NotEmpty.name,NotEmpty.java.lang.String,NotEmpty];

arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [memberForm.name,name];

arguments [];

default message [name]];

default message [회원 이름은 필수입니다.]

 

 

발생 원인

@NotEmpty를 선언한 name field가 공란으로 submit됨

 

 

해결 방법

name field에 값 입력

⭕ name값 미입력 시, Whitelabel Error Page로 이동하는 것이 아닌 입력 필요 안내 문구 Load

 name값 미입력 시, submit 버튼이 클릭될 수 없도록 로직 생성