相关疑难解决方法(0)

无法在Spring Data Repository中创建自定义查询方法

我想创建自定义存储库:

public interface FriendRepositoryCustom {

    Page<Friend> findFriends(FriendCriteria friendCriteria, Pageable pageable);
}
Run Code Online (Sandbox Code Playgroud)

及其实现:

@Repository
@Transactional(readOnly = true)
public class FriendRepositoryCustomImpl implements FriendRepositoryCustom {

    @PersistenceContext
    EntityManager entityManager;

    @Override
    public Page<Friend> findFriends(FriendCriteria friendCriteria, Pageable pageable) {
    ...
    }
Run Code Online (Sandbox Code Playgroud)

并将其添加到主存储库:

@Repository
public interface FriendRepository extends JpaRepository<Friend, Long>, JpaSpecificationExecutor<Friend>, FriendRepositoryCustom {

}
Run Code Online (Sandbox Code Playgroud)

当我启动应用程序时,出现此错误:

由以下原因引起:org.springframework.data.mapping.PropertyReferenceException:未找到类型为Friend的属性findFriends!在org.springframework.data.mapping.PropertyPath。(PropertyPath.java:77)在org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)在org.springframework.data.mapping.PropertyPath.create( org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)上的PropertyPath.java:309)org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)上的org.springframework.data org.springframework.data.repository.query.parser.PartTree $ OrPart。(PartTree.java:247)的org.springframework.data.repository.query的.repository.query.parser.Part。(Part.java:76) org.springframework.data.repository的.parser.PartTree $ Predicate.buildTree(PartTree.java:398)。

java hibernate spring-data-jpa spring-boot jhipster

6
推荐指数
1
解决办法
2462
查看次数

标签 统计

hibernate ×1

java ×1

jhipster ×1

spring-boot ×1

spring-data-jpa ×1