spring 是什么导致“找不到类型的属性”弹簧数据 jpa 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14066039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What caused the "No property find found for type" spring data jpa error
提问by Pete_ch
the error No property find found for type com.gridsearch.entities.Film
错误未找到类型 com.gridsearch.entities.Film 的属性
my repository
我的仓库
package com.gridsearch.repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.CrudRepository;
import com.gridsearch.entities.Film;
public interface FilmRepository extends CrudRepository<Film,Short>{
public Page<Film> findAll(Pageable page);
public Film findOne(short Id);
}
my service
我的服务
package com.gridsearch.service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import com.gridsearch.entities.Film;
public interface FilmService {
public Page<Film> allFilms(Pageable page);
public Film findOne(int Id);
}
my service implementation
我的服务实现
package com.gridsearch.service;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.gridsearch.entities.Film;
import com.gridsearch.repository.FilmRepository;
@Repository
public class FilmServiceImpl implements FilmService{
@Autowired
private FilmRepository repository;
@Transactional
public Page<Film> allFilms(Pageable page) {
return repository.findAll(page);
}
@Override
public Film findOne(int id) {
return repository.findOne((short) id);
}
}
回答by Ken Chan
It should be Shortinstead of short:
它应该是Short而不是short:
public Film findOne(Short Id);
By the way , you can simply extend PagingAndSortingRepositorywhich already provides the method findAll(Pageable page):
顺便说一下,您可以简单地扩展PagingAndSortingRepository已经提供了方法的findAll(Pageable page):
public interface FilmRepository extends PagingAndSortingRepository<Film,Short>{
}
回答by Pete_ch
I know the question has been answered but I got the same problem because I left an old method in my repository like
我知道问题已得到解答,但我遇到了同样的问题,因为我在存储库中留下了一个旧方法,例如
public List<Entity> findByDateBetween(Long a, Long b)
while "date" column didn't exist anymore in my database.
而“日期”列在我的数据库中不再存在。

