You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring报错:类型Product不存在prod属性 | Spring新手技术求助

解决Spring Error: No property prod found for type Product

Hey there, let's work through this Spring error you're hitting! The message "No property prod found for type Product" means Spring Data JPA is trying to look up a property named prod on your Product entity, but it doesn't exist—your entity has properties like prod_name, prod_desc, etc., instead. Here are the most common fixes:

1. Fix Repository Query Method Names

This is the #1 culprit. If you've defined a method in your ProductRepository like this (which references a non-existent prod property):

public interface ProductRepository extends JpaRepository<Product, Integer> {
    // Wrong! No "prod" property exists
    List<Product> findByProd(String prod);
}

You need to update the method name to match one of your actual entity properties. For example:

  • To query by product name: List<Product> findByProd_name(String prodName);
  • To query by product brand: List<Product> findByProd_brand(String brand);

Or if you prefer using camelCase (Spring can automatically map camelCase method names to underscored entity properties if your config is set up for it), you can write:

// Also works if your Spring config handles underscore-to-camelCase mapping
List<Product> findByProdName(String prodName);

2. Correct JPQL/HQL Query Statements

If you're using @Query annotations with custom JPQL, double-check that you're referencing valid entity properties. For example, this query would throw the error because it uses p.prod:

@Query("SELECT p FROM Product p WHERE p.prod = :value")
List<Product> findByProdValue(@Param("value") String value);

Fix it by replacing p.prod with a real property from your Product class, like p.prod_name or p.prod_brand:

@Query("SELECT p FROM Product p WHERE p.prod_name = :name")
List<Product> findByProdName(@Param("name") String name);

3. Verify Your Entity Class Completeness

Looking at your provided Product code, the last line cuts off at private i...—make sure your entity class is fully written with no incomplete property declarations. Even a typo or unfinished line could cause Spring to misinterpret your entity's structure. For example, if you meant to add a prod_stock property, ensure it's properly declared:

@NotNull
private int prod_stock; // Complete the property definition

Once you fix these areas, the error should disappear. Let me know if you need more details on any of these steps!

内容的提问来源于stack exchange,提问作者Rheza001

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:49:05