我想编写一个返回分页和排序实体列表的方法,我希望Spring Data可以直接从方法名称派生查询。来自共享模块的以下存储库定义在一个模块中使用时效果很好,并且在"上下文初始化失败时失败"在另一个人中使用时出错。
SELECT name, type FROM data.myData
WHERE type='01' OR type='02' OR type='03' OR
GROUP BY name, type
ORDER BY name, type
第一个模块更新,它依赖于Spring Data JPA 1.11.0 + Spring Data Commons 1.13.0。第二个模块较旧,它依赖于Spring Data JPA 1.6.2 + Spring Data Commons 1.8.2。
这是一块日志:
@Repository
public interface AppleDao extends JpaRepository<Apple, Long> {
Page<Apple> getAllByVarietyEqualsOrderById(Variety variety, Pageable pageable);
}
如何重写此方法,以便它可以在所有版本的Spring Data中正常运行?
答案 0 :(得分:0)
无需重写任何内容,只需指定明确的排序顺序(SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'appleServiceImpl': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private by.naxa.dao.apple.AppleDao by.naxa.services.apple.AppleServiceImpl.appleDao;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appleDao': Invocation of init method failed;
nested exception is java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract org.springframework.data.domain.Page by.naxa.dao.apple.AppleDao.getAllByVarietyEqualsOrderById(by.naxa.entity.apple.Variety,org.springframework.data.domain.Pageable)!
Invalid order syntax for part Id
或Asc
):
Desc
由于DATACMNS-641(修复了),您遇到此错误 Spring Data Commons 1.10)。