java - QueryDSL Unexpected Token , with any() and in clause -


i have 2 models, location , locationattribute, many many relationship. have list of locationattribute ids, , find locations have @ least 1 of attributes.

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; } 

locationattribute.java:

@entity public class locationattribute {      @id     @generatedvalue     @column(name="location_attribute_id")     protected int id; } 

i tried following querydsl code:

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); 

the code works fine if locationattributeids has 0 or 1 elements. however, when have more 1 element, error:

java.lang.illegalargumentexception: org.hibernate.hql.internal.ast.querysyntaxexception: unexpected token: , near line 5, column 53 [select location ch.locatee.test.querydslerror.locatee.location location exists (select location_locationattributes_cc6d8 location.locationattributes location_locationattributes_cc6d8 location_locationattributes_cc6d8.id in :x1_0_, :x1_1_, :x1_2_)]     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1750)     @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1677)     @ org.hibernate.jpa.internal.queryimpl.getresultlist(queryimpl.java:458)     @ com.mysema.query.jpa.impl.abstractjpaquery.getresultlist(abstractjpaquery.java:194)     @ com.mysema.query.jpa.impl.abstractjpaquery.list(abstractjpaquery.java:246)     @ ch.locatee.test.querydslerror.locatee.apptest.testsomething(apptest.java:63) 

i found quite few related sites question not sure how fix problem.

i made quick test project, can find on github: https://github.com/bekoeppel/querydslinerrortest. mvn test produces above error.

i appreciate ideas how can find locations have @ least 1 of locationattribute.ids list. thanks!

use following jpaquery constructor instead

new jpaquery(entitymanager); 

jpqltemplates provides generic serialization, doesn't find of hibernate's jpql variations. entitymanager argument querydsl pick right jpqltemplates subclass instance you.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -