노트코드
노트코드
노트코드

블로그 메뉴

  • 홈
  • 이력서
  • 이전 블로그
  • 글쓰기
  • 관리자페이지
  • 분류 전체보기 (57)
    • 코틀린 (2)
      • 실무 프로젝트로 배우는 Kotlin & Sprin.. (2)
    • JAVA (1)
      • 디자인패턴 (1)
      • 객체지향 5대원칙 (0)
    • SPRING (32)
      • JPA (11)
      • 스프링시큐리티 (1)
      • 스프링 (8)
      • QueryDsl (1)
      • 스프링배치 (11)
    • AZURE (0)
    • ETC (10)
      • MAVEN (0)
      • GIT (0)
      • ReMind (3)
      • Exception (1)
      • CS (6)
    • 책 (8)
      • 이것이 자바다 (8)

최근 글

최근 댓글

태그

  • JPA
  • 스프링
전체 방문자
오늘
어제
hELLO · Designed By 정상우.
노트코드

노트코드

SPRING/JPA

[JPA]스프링 데이터 Common:커스텀 리포지토리

2022. 1. 21. 01:59

쿼리 메소드로 해결이 되지 않는 경우 직접 코딩으로 구현가능

  • 스프링 데이터 리포지토리 인터페이스에 기능 추가
  • 스프링 데이터 리포지토리 기본 기능 덮어쓰기 가능
  • 구현 방법
    1. 커스텀 리포지토리 인터페이스 정의
    2. 인터페이스 구현 클래스 만들기(기본 접미어는 IMPL)
    3. 엔티티 리포지토리에 커스텀 리포지토리 인터페이스 추가
public Interface PostCustomRepository extends JpaRepository<Post,Long>, PostcustomRepository{
	List<Post> findMyPost();
}

기본 기능도 사용하되 일부 기능은 Override하여 나의 입맛에 맞게 수정하여 사용함

@Repository
@Transactional
public class PostcustomRepositoryImpl implements PostcustomRepository{
	@AutoWired
	EntityManager entityManager;

	@Override
	public List<Post> findMyPost(){
		System.out.println("custom findMyPost");
		return entityManager.createQuery("SELECT p From Post As p").getResultList();
	}
}

구현체는 IMPL을 붙여줘야함

만약 IMPL을 사용하기 싫으면 아래와 같이 수정해주면됨

@SpringBootapplication
@EnableJpaRepositories(repositoryImplementationPostfix="Default")
public class Application{
	public static void main(String[] args]{
		SpringApplication.run(Application.class)
	}
}

 

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

[JPA] 연관관계  (0) 2022.02.09
[JPA]객체지향쿼리  (0) 2022.02.09
[JPA]MappedSuperClass  (0) 2022.01.21
[JPA] 프록시  (0) 2022.01.21
[JPA]객체지향 쿼리 심화  (0) 2022.01.21
    'SPRING/JPA' 카테고리의 다른 글
    • [JPA] 연관관계
    • [JPA]객체지향쿼리
    • [JPA]MappedSuperClass
    • [JPA] 프록시
    노트코드
    노트코드
    노션 블로그에서 티스토리로 이전공사중

    티스토리툴바