문제
나는 다음과 같은 MySQL 책:
"SELECT * FROM $this->tableName WHERE news_publication_id = '" + newsPublicationId + "' AND list_order > '" + listOrder +"' ORDER BY list_order LIMIT 1"
나에서 시작된 데이터 처리하여 경로를 먼저 하고 있는 최대 절전 모드는 DAO 레이어입니다.
그 다음 기준에 기반 방법:
@Override
public NewsHeading findNextWithListOrder(NewsPublication newsPublication, int listOrder) {
Criteria criteria = getSession().createCriteria(getPersistentClass());
criteria.add(Restrictions.eq("newsPublication", newsPublication));
criteria.add(Restrictions.gt("listOrder", listOrder)).addOrder(Order.asc("listOrder")).setMaxResults(1);
return (NewsHeading) criteria.uniqueResult();
}
그것이 잘 작동합니다.
을 하 JPA2 저장소 계층입니다.
그것은 지금 다음과 같은 JPQL 기반 방법:
@Query("SELECT nh FROM NewsHeading nh WHERE nh.newsPublication = :newsPublication AND nh.listOrder > :listOrder ORDER BY nh.listOrder ASC LIMIT 1")
public NewsHeading findByNextListOrder(@Param("newsPublication") NewsPublication newsPublication, @Param("listOrder") int listOrder);
하지만 그것은 작동하지 않습니다.기 때문에 제한 조항이 유효하지 않습니다.
그래서 제가 궁금해 무엇을 할 수 있습니다.
할 수 있습니 계속 사용 기준에 기반 방법의 위에 이 JPA2 저장소 계층?
고 싶을 피하는 신뢰하는 클라이언트를 통과한 가치와 선호하는 코드는 해당 값(1)으로 레이어입니다.
또한,는 문이 하나만 반환합체이 없다 그래서 매김 필요합니다.
모든 제보는 것이 가장 환영합니다.
종류 감사합니다,
스테판 Eybert
해결책
할 수 있습니다 아마도 이와 PageRequest
. http://docs.spring.io/spring-data/jpa/docs/1.6.2.RELEASE/reference/html/repositories.html#repositories.core-concepts
최대 절전 모드 원하는 것을 할 setMaxResults()
에 Query
객체지만,JPA 지 않는 인터페이스와 함께하는 직접 있습니다.
다른 옵션을 사용하는 것입니다 @NamedNativeQuery
제휴하지 않습니다 StackOverflow