사용자 도구

사이트 도구


java:jpa:springdatajpa

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
java:jpa:springdatajpa [2019/04/22 14:36]
kwon37xi
java:jpa:springdatajpa [2020/12/23 12:55]
kwon37xi
줄 34: 줄 34:
 } }
 </code> </code>
 +
 +===== Repository 상속 금지 =====
 +  * 멀티 모듈 프로젝트에서 ''BoardRepository''가 도메인 모듈에 있을 때, API 모듈에서 이를 상속해서 ''BoardApiRepository'' 처럼 만들거나 하는 경우가 발견됨. **절대 상속하지 말 것**
 +  * 이 경우 도메인 모듈과 말단 모듈의 Repository가 둘다 Custom 구현을 필요로 할 경우 제대로 작동안하게 된다.
 +  * 또한, 메소드 이름 겹칠 때 뭘 선택하게 되는지 불확실한 등 문제가 많다.
 +  * 꼭 말단 모듈에서 Repository 메소드를 도메인모듈과 격리해서 구현하고자 한다면 **상속 없이 별개의 Repository로 따로 만든다.**
  
 ===== Native Query ===== ===== Native Query =====
줄 141: 줄 147:
   * interface 기반으로 projection 가능.   * interface 기반으로 projection 가능.
  
 +===== @Query에 SpEL 지원 =====
 +  * [[https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions|SpEL support in Spring Data JPA @Query definitions]]
  
 +<code java>
 +@Query("select u from User u where u.age = ?#{[0]}")
 +List<User> findUsersByAge(int age);
 +
 +@Query("select u from User u where u.firstname = :#{#customer.firstname}")
 +List<User> findUsersByCustomersFirstname(@Param("customer") Customer customer);
 +</code>
  
 ===== 참조 ===== ===== 참조 =====
java/jpa/springdatajpa.txt · 마지막으로 수정됨: 2024/02/07 14:43 저자 kwon37xi