java - Stop the JPA (Hibernate) Criteria API creating repeated INs for a group of OR Predicates -


i'm using criteria api hibernate implementation of jpa. want improve structure of generated sql query same in expression isn't repeated each or predicate.

i want because code running on gae , stackoverflowerror in case list of names long in in condition (it's due hibernate using stringbuilder build parameter list). i've pinned problem down section of code when remove, 8, of or predicates code runs without error. code runs fine on non-memory restrictive environments (my pc)....and yes have increased instance memory allocation on gae still same error.

the java code have build part of query below (parameter names edited , i'm using @staticmetamodel classes parameter names):-

private void buildnamestoquery(list<string> names, root<aroot> theroot,         join<entity1, entity2> ajoin, list<predicate> orpredicates) {      orpredicates.add(ajoin.get(entity1_.name1).in(names));     orpredicates.add(ajoin.get(entity1_.name2).in(names));     orpredicates.add(ajoin.get(entity1_.name3).in(names));     orpredicates.add(ajoin.get(entity1_.name4).in(names));      orpredicates.add(theroot.get(entity2_.name5).in(names));     orpredicates.add(theroot.get(entity2_.name6).in(names));     orpredicates.add(theroot.get(entity2_.name7).in(names));     orpredicates.add(theroot.get(entity2_.name8).in(names));     orpredicates.add(theroot.get(entity2_.name9).in(names));     orpredicates.add(theroot.get(entity2_.name10).in(names)); } 

this generates sql following structure (parameter names edited):-

select       //lots of detail select       //lots of condition detail     //but i'm interested in below   , (     entity_.name1 in (?,?,?....     ) //lots of names     or entity_.name2 in (?,?,?....     ) //same list of names     or entity_.name3 in (?,?,?...     ) //same list of names again   //.   //continues remainder of query   // ); 

how can change criteria api code sql becomes this?:-

and (    joinentity_.name1 or joinentity.name2 or joinentity.name3 ... etc in (?,?,?...)  

with same long list of names? that's clear enough suggest solution.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -