使用 IN & MEMBER OF 子句通过 JPQL 获取数据时,操作数应包含 2 列
Operand should contain 2 column(s) when fetching data through JPQL using IN & MEMBER OF clause
我正在尝试获取创建查询的员工可用性数据。我使用@ElementCollection 注释来映射技能和daysAvailable,它将数据存储到其他table.
TypedQuery<Employee> query = entityManager.createQuery("select e from Employee e where :day MEMBER OF e.daysAvailable and :list MEMBER OF e.skills ", Employee.class);//
query.setParameter("day", dayOfWeek);
query.setParameter("list", employeeRequestDTO.getSkills());
List<Employee> list = query.getResultList();
我正在尝试在我的查询中传递一个集合。如果集合中只有一个元素,则查询有效,但如果多于 1,则无法获取。我尝试在 (:list) 中使用 e.skills 而不是
:列出 e.skills 的成员。但是还是没有运气!!
@Entity
public class Employee {
@Id
@GeneratedValue
private long id;
@Nationalized
private String name;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "skills", joinColumns = @JoinColumn(name = "emp_id"))
@Enumerated(EnumType.STRING)
private Set<EmployeeSkill> skills;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "days", joinColumns = @JoinColumn(name = "emp_id"))
@Enumerated(EnumType.STRING)
private Set<DayOfWeek> daysAvailable;
// Getters & Setters
这是我创建的域,现在想要获取在特定日期有空并具有特定技能的所有员工。我已经为此创建了查询,但它显示错误 - java.sql.SQLException: Operand should contain 2 column(s)
这是生成的查询-
select * from employee e where ( 'TUESDAY' in ( select d.days_available from days d where e.id=d.emp_id)) and (( 'PETTING','FEEDING' ) in (select s.skills from skills s where e.id=s.emp_id));
有什么建议吗?
在 JPQL 中,MEMBER OF
采用单个参数并检查它是否包含在提供的集合中。
查看 Hibernate User Guide 了解更多详情。
试试这个查询:
select e
from Employee e
join e.skills s
where
:day MEMBER OF e.daysAvailable and
s in :list
我正在尝试获取创建查询的员工可用性数据。我使用@ElementCollection 注释来映射技能和daysAvailable,它将数据存储到其他table.
TypedQuery<Employee> query = entityManager.createQuery("select e from Employee e where :day MEMBER OF e.daysAvailable and :list MEMBER OF e.skills ", Employee.class);//
query.setParameter("day", dayOfWeek);
query.setParameter("list", employeeRequestDTO.getSkills());
List<Employee> list = query.getResultList();
我正在尝试在我的查询中传递一个集合。如果集合中只有一个元素,则查询有效,但如果多于 1,则无法获取。我尝试在 (:list) 中使用 e.skills 而不是 :列出 e.skills 的成员。但是还是没有运气!!
@Entity
public class Employee {
@Id
@GeneratedValue
private long id;
@Nationalized
private String name;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "skills", joinColumns = @JoinColumn(name = "emp_id"))
@Enumerated(EnumType.STRING)
private Set<EmployeeSkill> skills;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "days", joinColumns = @JoinColumn(name = "emp_id"))
@Enumerated(EnumType.STRING)
private Set<DayOfWeek> daysAvailable;
// Getters & Setters
这是我创建的域,现在想要获取在特定日期有空并具有特定技能的所有员工。我已经为此创建了查询,但它显示错误 - java.sql.SQLException: Operand should contain 2 column(s)
这是生成的查询-
select * from employee e where ( 'TUESDAY' in ( select d.days_available from days d where e.id=d.emp_id)) and (( 'PETTING','FEEDING' ) in (select s.skills from skills s where e.id=s.emp_id));
有什么建议吗?
在 JPQL 中,MEMBER OF
采用单个参数并检查它是否包含在提供的集合中。
查看 Hibernate User Guide 了解更多详情。
试试这个查询:
select e
from Employee e
join e.skills s
where
:day MEMBER OF e.daysAvailable and
s in :list