我在春季3,jpa,eclipse链接,弹簧数据中都有简单的webapp。当我尝试运行它(在VMware服务器上)时,我遇到了错误:
org.springframework.data.mapping.PropertyReferenceException: No property show found for type foo.domain.Catalog
实体:
@Entity
@Table(name="catalog")
@NamedQuery(name="Catalog.findAll", query="SELECT c FROM Catalog c")
public class Catalog implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private String id;
private String adres;
private String opis;
private String tytul;
//bi-directional many-to-one association to Category
@ManyToOne
@JoinColumn(name="cname", referencedColumnName="name")
private Category category;
public Catalog() {
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getAdres() {
return this.adres;
}
public void setAdres(String adres) {
this.adres = adres;
}
public String getOpis() {
return this.opis;
}
public void setOpis(String opis) {
this.opis = opis;
}
public String getTytul() {
return this.tytul;
}
public void setTytul(String tytul) {
this.tytul = tytul;
}
public Category getCategory() {
return this.category;
}
public void setCategory(Category category) {
this.category = category;
}
接口库:
public interface KatalogRepository extends JpaRepository<Catalog, Long>{
@Query("select c from Catalog c left join fetch c.name")
public List<Catalog> showAll();
@Query("select c from Catalog c where c.tytul like %?1")
public Catalog findByTytul(String tytul);
@Query("select c from Category c")
public List<Category> showAllCategory();
@Query("select c from Category c where c.id =:id")
public Category findCategoryById(Long id);
}
我尝试了很多解决方案但没有帮助。有人有类似的问题吗?谢谢你的帮助。
我的道教课程:
@Repository
public class KatalogDAO {
@Autowired
KatalogRepository katalogRepository;
//@Autowired
//CategoryRepository categoryRepository;
@Transactional
public List<Catalog> showAllSites(){
return katalogRepository.showAll();
}
@Transactional
public void saveSite(Catalog catalog){
katalogRepository.saveAndFlush(catalog);
}
@Transactional
public Catalog showByTitle(String tytul){
return katalogRepository.findByTytul(tytul);
}
@Transactional
public List<Category> showAllCategory(){
return katalogRepository.showAllCategory();
}
@Transactional
public Category findCategoryById(Long id){
return katalogRepository.findCategoryById(id);
}
}
终点:
@Component
public class CatalogEndpoint {
@Autowired
KatalogDAO katalogDAO;
public List<Catalog> showAllSites(){
return katalogDAO.showAllSites();
}
public void saveSite(Catalog catalog ){
katalogDAO.saveSite(catalog);
}
public Catalog getByTitle(String tytul){
return katalogDAO.showByTitle(tytul);
}
public List<Category> showCategory(){
return katalogDAO.showAllCategory();
}
public Category findCategoryById(Long id){
return katalogDAO.findCategoryById(id);
}
}
答案 0 :(得分:0)
我认为问题在于你写了这个查询:
@Query("select c from Category c")
应该是:
@Query("select * from Category c")
错误可能是由Spring Data JPA框架引起的,因为如果你给它一个错误的请求,它可能会尝试根据方法名称生成一个请求,但在这种情况下,你的方法名称应该是“findAll” ”。此外,由于CRUDRepository接口,Spring Data JPA框架已经提供了findAll()方法。