반응형

2020/11/06 3

Class com.querydsl.core.types.QBean can not access a member of class "entity" with modifiers "protected"

JPA, Querydsl을 학습하는 도중 com.querydsl.core.types.QBean com.example.queyrdsl.entity.Staff with modifiers "protected" 라는 Exception이 발생했다. querydsl 사용중 QBean에서 Entity객체인 Staff를 생성하려한다. 하지만 Staff 클래스는 Access = Protected였다. 그래서 위와같은 에러가 발생하였다. @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED)// 이 부분이 문제 public class Staff { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) privat..

TroubleShooting 2020.11.06

Multiple representations of the same entity [com.example.queyrdsl.entity.Staff#2] are being merged

JPA 정리 도중 에러 발생! Repository를 이용하여 save할 시 발생했던 에러다. 원인은 간단하다. @OneToMany 관계에서 Many에 해당하는 Entity를 save할때 문제가 발생했다. Entity는 고유하다! 하지만 난 2개의 Entity @Id 컬럼에 같은 값을 넣고 save하는 중이었다. JPA가 같은 Entity가 들어왔으니 위와 같은 에러를 보여준 것이다. 해결은 @Id 컬럼의 값을 수정했다.

TroubleShooting 2020.11.06

Spring Data JPA 기반 Querydsl란?

이제서야 적용해본다 Querydsl!! 기존 프로젝트에서는 mybatis를 사용했다. mybatis는 Mapper.java, mapper.xml 파일을 만들어 namespace로 연결하여 사용하는 방식이었다. 개발자1로써 크게 불편함을 느끼지 않고 쓰고 있었다. 그런데 Querydsl이 나오고 신세계를 경험했다. Querydsl 장점 대표적으로 type-safe이다. 자세한 내용은 밑에서 다루겠습니다. 잘못된 쿼리를 xml에 작성 후 build해도 에러는 발생하지 않는다. 실제 쿼리를 호출해야 그제서야 에러가 발생한다. 이런 문제를 사전에 방지 할 수 있다. SELECT * FROM store -- xml에서는 에러 발생하지 않는다. java의 enum, constant를 이용해 type이 의미하는 바를..

Develop/spring-data 2020.11.06
728x90
반응형