java – 无法在Spring Data Repository中创建自定义查询方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 无法在Spring Data Repository中创建自定义查询方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2082字,纯文字阅读大概需要3分钟。
内容图文
![java – 无法在Spring Data Repository中创建自定义查询方法](/upload/InfoBanner/zyjiaocheng/707/76722bec0e38441499d3ba8664dec3d9.jpg)
参见英文答案 > How to add custom method to Spring Data JPA 11个
我想创建自定义存储库:
public interface FriendRepositoryCustom {
Page<Friend> findFriends(FriendCriteria friendCriteria, Pageable pageable);
}
它的实施:
@Repository
@Transactional(readOnly = true)
public class FriendRepositoryCustomImpl implements FriendRepositoryCustom {
@PersistenceContext
EntityManager entityManager;
@Override
public Page<Friend> findFriends(FriendCriteria friendCriteria, Pageable pageable) {
...
}
并将其添加到主存储库:
@Repository
public interface FriendRepository extends JpaRepository<Friend, Long>, JpaSpecificationExecutor<Friend>, FriendRepositoryCustom {
}
当我启动应用程序时,我收到此错误:
Caused by:
org.springframework.data.mapping.PropertyReferenceException: No
property findFriends found for type Friend! at
org.springframework.data.mapping.PropertyPath.(PropertyPath.java:77)
at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
at
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
at
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)
at
org.springframework.data.repository.query.parser.Part.(Part.java:76)
at
org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:247)
at
org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398)
at
org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:378)
at
org.springframework.data.repository.query.parser.PartTree.(PartTree.java:86)
at
org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:70)
… 43 common frames omitted
解决方法:
您可能错误地命名了您的实现类.
请注意,命名期望随Spring Data 2.0而变化.
对于< 2.0必须将实现命名为具有附加Impl后缀的最终存储库接口. See the matching reference documentation for an example.
对于> = 2.0,必须将实现命名为具有附加Impl后缀的自定义接口. See the current reference documentation for an example.
注意:您不需要任何@Repository注释.
内容总结
以上是互联网集市为您收集整理的java – 无法在Spring Data Repository中创建自定义查询方法全部内容,希望文章能够帮你解决java – 无法在Spring Data Repository中创建自定义查询方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。