2016-05-23 45 views
1

檢索信息,以便可以說我有以下兩類:JPA - 從連接表

@Entity 
public class Reservation extends Observable implements Serializable { 

@Id 
@GeneratedValue(strategy=GenerationType.AUTO) 
private Long id; 

private static final long serialVersionUID = 1L; 

@ManyToOne(cascade = CascadeType.MERGE) 
private ReservationState state; 

@ManyToOne(cascade = CascadeType.MERGE) 
private CafeteriaUser user; 

@ManyToOne(cascade = CascadeType.ALL) 
@JoinColumn(name="idMeal",referencedColumnName= "idMeal") 
private Meal meal; 

而且

@Entity 
public class Meal implements Serializable { 

private Price price; 
private MealType mealType; 
private Dish m_dish; 

@Temporal(javax.persistence.TemporalType.DATE) 
private Calendar date; 

@ManyToOne (cascade = CascadeType.ALL) 
private Menu menu; 

@Id 
@GeneratedValue(strategy = GenerationType.AUTO) 
private Long idMeal; 

public Meal() { 
} 

現在,我有麻煩「連接」這兩個表。在JPQL中,與給定日期(select * from Reservation r,Meal m,其中r.idMeal = m.IDMEAL和m。「DATE」='2016-01-01')相等,

它似乎使用r.idMeal = m.idMeal給我「集合值路徑'r.idMeal'無法解析爲有效的關聯字段。」錯誤

+0

r.idMeal不是收藏價值的路徑(根據您發佈的內容)。然而,r.idMeal是一個Meal對象,而m.idMeal是一個Long ...因此它們不具有可比性 –

回答

1

基本JPQL會是這樣

SELECT r FROM Reservation r JOIN r.meal m WHERE m.date = :date 

,並通過在日期作爲參數。這應該從絕大多數JPQL教程中顯而易見