엔티티은 다음과 같습니다사용자 정의 쿼리 봄의 데이터 JPA
제품 표
@Entity
public class Product implements Serializable {
/*@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@NotNull(message = "Product name must not be null")
@NotEmpty
private String name;
@ManyToOne
@JoinColumn(name="category_id")
private Category category;
@ManyToMany(mappedBy = "productlist")
private List<OrderDetail> orderDetail =new ArrayList<OrderDetail>();
//getters setter
OrderDetail 표
@Entity
public class OrderDetail {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ManyToOne
@JoinColumn(name="purchased_By")
private user PurchasedBy;
@ManyToMany
private Set<Product> productlist = new HashSet<Product>();
이 실체 'order_detail_productlist'로 명명 된 및 다음 order_detail_id 등의 분야와 내가 MySQL의 편집기에서 쿼리를 다음 실행하고 그리고 그
select u.id, r.name from order_detail u inner join order_detail_productlist ur on(u.id=ur.order_detail_id) inner join product r on(ur.productlist_id=r.id) where u.id="?"
작동 되나
을 productlist_id 내가 나에게 예외를주고있다 @query 주석 봄 저장소에 실행할 때. 엔티티에 따라 Order_detail의 이름을 OrderDetail로 변경하려고했으나 두 경우 모두 동일한 예외가되었습니다.
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [select r.name from com.example.Domain.OrderDetail u inner join order_detail_productlist ur on(u.id=ur.order_detail_id) inner join Product r on(ur.productlist_id=r.id) where u.id= :id ]
내가 원하는 것. 이 방법으로 사용하려고합니다.
public final static String product_ordered ="select r.name from OrderDetail u inner join order_detail_productlist ur " +
"on(u.id=ur.order_detail_id) inner join Product r" +
" on(ur.productlist_id=r.id)" +
" where u.id= :id ";
@Query(product_ordered)
public List<Product> findById(@Param("id") int id);
나는 여러 테이블에서 데이터를 가져오고 싶습니다.