inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

실전! 스프링 부트와 JPA 활용2 - API 개발과 성능 최적화

스프링 데이터 JPA 소개

스프링 데이터 JPA 와 EntityManager

480

작성자 없음

작성한 질문수 0

0

안녕하세요 영한님 강의 잘 들었습니다! 

 

제가 Data JPA랑 entity Manager 같이 쓰려고

public interface WorkerRepository extends JpaRepository<Worker, Long>,CustomRepository{}

위와 같이 CustomRepository 인터페이스를 만들고 구현체 클래스에서 Entity Manager를 주입받고 썼는데 에러가 나서 제가 진행하는 방법이 잘 못 되었는지 질문 드립니다..

JPA java spring-boot spring

답변 4

2

차가운물

코드는 강의와 관련된 부분이 아니지만 제가 한 질문은 강의와 관련된 질문인 것 같아서 질문 올려봤습니다.

주제와 벗어났다면 주의하도록 하겠습니다.

 

답변 감사합니다.!!

0

David

이해해주셔서 감사합니다.

2

David

안녕하세요. Jeongmin Lee님, 공식 서포터즈 David입니다.

.
자세한 코드와 오류 내용을 함께 올려주세요
.
감사합니다.

0

차가운물

안녕하세요 답글이 늦었습니다.

먼저 도움 주셔서 감사합니다.

 

소스코드

https://drive.google.com/file/d/1nlV_PJWleiY05kyEMMkkGV_zqpENjrbM/view?usp=sharing

 

실행방법 :

mysql DB를 준비해 주시고

application.yml 파일에 datasource를 넣어주세요.

그리고 main문을 실행하시면 됩니다.

 

2.문제를 확인하는 법

메인 문을 실행하시면 바로 에러가 나옵니다.

 

제가 질문드리는 것은 JPARepository와 EntityManager를 함께 쓸 수 있는 방법 입니다.

프로젝트에서 WorkerRepository에 가시면 CustomRepository를 상속한 것을 볼 수 있을 것 입니다.

CustomRepository를 구현한 구현체 CustomRepositoryImp에 EntityManager를 주입받고 em을 쓰려고 했지만 잘 안되는 상태입니다.

 

감사합니다.

0

David

코드를 살펴보았는데 강의와  관련된 내용이 아니시네요.

최대한 강의와 관련된 내용으로 질문 부탁드립니다.

 

WorkerService에 WorkerRepository를 주입받아야 하는데 그러지 못하고 있습니다.

WorkerRepository 타입의 빈을 생성하는 부분에서 문제가 발생한 것 같습니다.

WorkerRepository가 CustomRepository를 상속받고 있는데 CustomRepository 내 정의된 customMethod와 관련된 쿼리를 생성하지 못해서 빈 생성에 실패하는걸로 보입니다.

이 부분을 해결하시면 다음 스텝으로 진행될 것 같습니다.

0

차가운물

넵 

 

public interface WorkerRepository extends JpaRepository<Worker, Long>,CustomRepository{

    Worker findByName(String name);

}
public interface CustomRepository {
    void customMethod();
}
@Service
public class CustomRepositoryImp implements CustomRepository{

    @Autowired
    private EntityManager em;

    @Override
    public void customMethod() {
        System.out.println("test");
    }

}

 

에러 메세지

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'workerService' defined in file [C:\Users\admin\git\rebuild\build\classes\java\main\com\rebuild\service\WorkerService.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'workerRepository' defined in com.rebuild.repository.WorkerRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract void com.rebuild.repository.CustomRepository.customMethod()! Reason: Failed to create query for method public abstract void com.rebuild.repository.CustomRepository.customMethod()! No property customMethod found for type Worker!; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract void com.rebuild.repository.CustomRepository.customMethod()! No property customMethod found for type Worker!

 

어플리케이션이 실행하되지 전에 에러나 나는 상태 입니다.

0

David

에러는 workService, workRepository가 생성될 때 발생했는데 관련 코드는 없으시네요.


전체 프로젝트를 압축해서 구글 드라이브로 공유해서 링크를 남겨주세요.
구글 드라이브 업로드 방법은 다음을 참고해주세요.

https://bit.ly/3fX6ygx

주의: 업로드시 권한 문제 꼭 확인해주세요

추가로 다음 내용도 코멘트 부탁드립니다.

1. 실행 방법을 알려주세요.
2. 어떻게 문제를 확인할 수 있는지 자세한 설명을 남겨주세요.

강의 관련 외 질문입니다.

0

68

2

SpringBoot4 + Hibernate7 모듈 등록 방법 공유

0

92

1

BeanCreationException

0

91

3

Update 후 UpdateMemberResponse 매핑할 때

0

50

1

트랜잭션을 사용 안 할 때 커넥션은 언제 가져오나요?

0

101

2

페이징 + 검색조건 관련해서 질문드립니다.

0

70

1

Query Dsl Q파일 질문입니다.

0

84

1

루트 쿼리라는것은

0

60

1

메서드를 분리하는 기준

0

65

1

findAllWithMemberDelivery 메서드 질문드립니다.

0

111

3

연관관계 매핑을 안 쓸 경우, 사용해야 하는 전략

0

86

2

fetch join과 영속화와 OSIV의 관계

0

87

2

Distinct 사용 전 결과에 대한 의문

0

117

2

레포지토리 계층에서의 트랜잭션에 대한 의문

0

59

1

영속성 컨텍스트 생명주기의 신기한 부분이 있습니다.

0

78

2

dto 필드 속 엔티티 여부

0

60

1

뷰템플릿 사용 시

0

77

2

Result 클래스 관련 질문

0

56

1

@PostConstruct 프록시 관련 질문드립니다

0

86

1

DTO 대신 Form 사용은 안되나요?

0

138

1

OSIV ON 상태일 때

0

96

1

fetch join VS fetch join 페이징 궁금증

0

187

2

양방향 연관관계 알아보는 법?

0

106

1

16강 17강 간단 정리 이게 맞을까요 ?

0

166

2