Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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
Java QueryDSL意外标记,带有any()和in子句_Java_Hibernate_Querydsl - Fatal编程技术网

Java QueryDSL意外标记,带有any()和in子句

Java QueryDSL意外标记,带有any()和in子句,java,hibernate,querydsl,Java,Hibernate,Querydsl,我有两个模型,Location和LocationAttribute,具有多对多关系。 我有一个LocationAttribute ID列表,希望找到至少有一个ID的所有位置 在这些属性中 Location.java: @Entity public class Location { @Id @GeneratedValue @Column(name="LOCATION_ID") protected int id; @ManyToMany(targetEnt

我有两个模型,
Location
LocationAttribute
,具有多对多关系。 我有一个LocationAttribute ID列表,希望找到至少有一个ID的所有位置 在这些属性中

Location.java:

@Entity
public class Location {

    @Id
    @GeneratedValue
    @Column(name="LOCATION_ID")
    protected int id;

    @ManyToMany(targetEntity = LocationAttribute.class)
    @JoinTable(name="LOCATION_TO_LOCATION_ATTRIBUTE",
            joinColumns = @JoinColumn(name="LOCATION_ID", referencedColumnName = "LOCATION_ID"),
            inverseJoinColumns = @JoinColumn(name="LOCATION_ATTRIBUTE_ID", referencedColumnName = "LOCATION_ATTRIBUTE_ID")
    )
    private List<LocationAttribute> locationAttributes;
}
我尝试了以下QueryDSL代码:

List<Integer> locationAttributeIds = new ArrayList<Integer>();
locationAttributeIds.add(1);
locationAttributeIds.add(2);
locationAttributeIds.add(3);

QLocation location = QLocation.location;
JPAQuery query = new JPAQuery(entityManager, JPQLTemplates.DEFAULT);
query.from(location) .where(location.locationAttributes.any().id.in(locationAttributeIds));
query.list(location);
我找到了很多与我的问题相关的网站,但不确定如何解决这个问题

我做了一个快速测试项目,你可以在Github上找到它:<代码>mvn测试产生上述错误


如果您能告诉我如何找到列表中至少有一个
LocationAttribute.id
s的所有
位置,我将不胜感激。谢谢

改用以下JPAQuery构造函数

new JPAQuery(entityManager);
JPQLTemplates
提供了通用的序列化,但没有找到Hibernate的所有JPQL变体。仅使用EntityManager参数Querydsl将为您选择正确的JPQLTemplates子类实例

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: , near line 5, column 53 [select location
from ch.locatee.test.querydslerror.locatee.Location location
where exists (select location_locationAttributes_cc6d8
from location.locationAttributes as location_locationAttributes_cc6d8
where location_locationAttributes_cc6d8.id in :x1_0_, :x1_1_, :x1_2_)]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1750)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.getResultList(AbstractJPAQuery.java:194)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:246)
    at ch.locatee.test.querydslerror.locatee.AppTest.testSomething(AppTest.java:63)
new JPAQuery(entityManager);