标签:jhipster java spring-boot spring-data-jpa hibernate
参见英文答案 > 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注释.
标签:jhipster,java,spring-boot,spring-data-jpa,hibernate 来源: https://codeday.me/bug/20190929/1830927.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。