-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
QueryDSL 관련해서 질문드립니다.
20.03.09 14:08 작성 조회수 152
0
안녕하세요. 강의를 듣던 중 테스트가 실패해야하는데 정상적으로 실행이 되어 질문드립니다.
25.스프링 데이터 Common: QueryDSL 에 관련된 질문입니다.
저와 같은 질문을 하신 분이 있던데(https://www.inflearn.com/questions/9020) 버전 변경으로 인해QuerydslJpaRepository 이 deprecated 되며 SimpleJpaRepository 를 변경하지 않고 사용할 repository 에 QuerydslPredicateExecutor 을 상속받아서 사용해도 되는지 문의드립니다.
하단에 코드 함께 첨부하였습니다.
@EnableJpaRepositories(repositoryBaseClass = SimpleMyRepository.class)
@NoRepositoryBean
public interface MyRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
boolean contains(T entity);
}
public class SimpleMyRepository<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements MyRepository<T, ID>{
private EntityManager entityManager;
private SimpleMyRepository(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
this.entityManager = entityManager;
}
@Override
public boolean contains(T entity) {
return entityManager.contains(entity);
}
}
public interface PostRepository extends MyRepository<Post, Long>, QuerydslPredicateExecutor<Post> {
}
@Test
public void crud() {
Post post = new Post();
post.setTitle("hibernate!");
postRepository.save(post.publish());
Predicate predicate = QPost.post.title.contains("hi");
Optional<Post> one = postRepository.findOne(predicate);
assertThat(one).isNotEmpty();
}
답변을 작성해보세요.
0
답변 1