【发布时间】:2017-02-25 06:51:36
【问题描述】:
我正在尝试实现加入,但我遇到了错误。我有产品表和商店表。 product表通过外键引用store表如下:
Product.java
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long pId;
private String model;
private String brand;
private byte[] image;
private Long price;
private String currency;
private String transmissionType;
private String fuelType;
@ManyToOne
@JoinColumn(name="storeId")
private Store store;
// … getters and setters
}
现在,我展示 Store.java
@Entity
public class Store {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long storeId;
private String locality;
private String city;
private String state;
private String zipCode;
private String phone;
// … getters and setters
}
现在,我展示存储库
public interface ProductRepo extends JpaRepository<Product, Long> {
@Query("select p from Product p join p.storeId s where p.storeId = s.storeId and s.city = :city")
public List<Product> findByCity(@Param("city") String city);
@Query("select p from Product p join p.storeId s where p.storeId = s.storeId and s.state = :state")
public List<Product> findByState(@Param("state") String state);
}
现在,错误是由于我实现连接的最后两个查询造成的。如上所示,我想要做的是获取商店位于特定城市或州的所有产品。
我遇到的错误是:
启动 ApplicationContext 时出错。显示自动配置 报告启用“调试”后重新运行您的应用程序。 2016-10-16 09:53:25.203 错误 16132 --- [主要] os.s.boot.SpringApplication : 应用启动失败
org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名为“catalogueServiceController”的 bean 时出错: 通过字段“productRepo”表示的不满足的依赖关系;嵌套的 例外是 org.springframework.beans.factory.BeanCreationException: 创建名为“productRepo”的 bean 时出错:调用 init 方法 失败的;嵌套异常是 java.lang.IllegalArgumentException: 查询方法 public abstract java.util.List 的验证失败 com.practice.rest.assignment1.repository.ProductRepo.findByCity(java.lang.String)! 等等....
我的查询有什么错误?
【问题讨论】:
标签: jpa spring-boot spring-data spring-data-jpa jpql