我使用JPA在JavaEE中编写后端。 我有一个带有列表的实体。
public class Lesson {
@Id
private String id;
private List<Time> times;
时间实体:
@Entity
public class Time {
@Id
@GeneratedValue
private int id;
private String assigned_room;
我想获得一个具有特定Assigned_room的课程列表。
例如:
课程:id = 1,次数{id:1,assigned_room:room123-id:2 Assigned_room_:room321-id:3 Assigned_room:room123}
然后,当我想随着时间的推移在room123中上所有课程时,我想要...我尝试过:
@NamedQuery(name = "Lesson.getWithRoomId", query = "select l from Lesson l where :id member of l.times")
但是发生以下错误:
Parameter value [room123] did not match expected type [... .entities.Time (n/a)]
有人知道如何解决错误或解决问题的方法吗? 谢谢!!
答案 0 :(得分:2)
问题出在您的member of
子句中,因为您提供了房间的ID,但是l.times
是类型Time
的集合。例如,您可以使用以下查询:
SELECT l FROM Lesson l JOIN l.times t WHERE t.assigned_room = :id