Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Spring JPA选择集合中的where元素_Mysql_Spring_Hibernate_Jpa_Kotlin - Fatal编程技术网

Mysql Spring JPA选择集合中的where元素

Mysql Spring JPA选择集合中的where元素,mysql,spring,hibernate,jpa,kotlin,Mysql,Spring,Hibernate,Jpa,Kotlin,我有一个实体人和一个实体会话。一个会话有一个@manytomy人的集合。现在,我想选择persons集合any会话中包含的所有人员。我尝试的是: @Query("select p from Person p where p in (select s.persons from Session s)") fun findAllInAnySession(): MutableIterable<Person> 我使用MySQL作为数据库 谢谢你的帮助 我认为您不能在in子句中

我有一个实体
和一个实体
会话
。一个
会话
有一个
@manytomy
人的集合。现在,我想选择
persons
集合any会话中包含的所有人员。我尝试的是:

    @Query("select p from Person p where p in (select s.persons from Session s)")
    fun findAllInAnySession(): MutableIterable<Person>
我使用MySQL作为数据库


谢谢你的帮助

我认为您不能在in子句中使用复杂对象,即使在JPQL中也是如此。您试图在查询中断言person实体是否是person集合的成员,这听起来可以接受,但我认为JPA提供者无法处理这样的查询。我认为以下查询可以返回您想要的内容:

select s, p from Sessions s join s.persons p

似乎您要选择与
会话关联的所有
人员
。您是否尝试过“从会话s中选择s.persons”
您是否可以将会话表重命名为其他名称,可能是mysql使用了该名称。
select s, p from Sessions s join s.persons p