当我尝试在浏览器上运行URL以获取所有产品时,我一直收到此“ SQLSyntaxErrorException:’field list’中的未知列’product0_.return_policy’”.
浏览器也显示以下内容:
There was an unexpected error (type=Internal Server Error, status=500).
could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
returnPolicy是导致此问题的唯一变量.当我同时从数据库和Java中的Product类中删除变量本身时,便能够从数据库中成功检索所有值.
这是RESTController的一部分的getAllProducts方法:
@RequestMapping(method=RequestMethod.GET, value="/products")
public List getAllProducts() {
return productService.getAllProducts();
}
当我完全删除returnPolicy变量时,它工作正常.
MySQL表说明是This:
存储在returnPolicy列中的值:
returnPolicy
0
0
1
1
1
这是“产品”模型变量的代码:
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="product")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
private int price;
private String vendor;
private String description;
private Boolean returnPolicy;
产品资料库
@Repository public interface ProductRepository extends JpaRepository{ }
SQL tinyint(Boolean)和Java的Boolean类型之间的映射是否存在问题?