0

我在 spring 3、jpa、eclipse 链接、spring 数据中有简单的 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);

    }
}
4

1 回答 1

0

我认为问题在于您编写了此查询:

@Query("select c from Category c")

应该是:

@Query("select * from Category c")

该错误可能是由 Spring Data JPA 框架引起的,因为如果你给它一个错误的请求,它可能会尝试根据方法名生成请求,但在这种情况下,你的方法名应该是“findAll”。此外,由于 CRUDRepository 接口,Spring Data JPA 框架已经提供了 findAll() 方法。

于 2013-08-31T07:54:23.043 回答