2323import java .util .Collection ;
2424import java .util .Date ;
2525import java .util .EnumSet ;
26- import java .util .List ;
2726import java .util .Set ;
2827import java .util .UUID ;
2928
3029import javax .persistence .criteria .CriteriaBuilder ;
3130import javax .persistence .criteria .Expression ;
3231import javax .persistence .criteria .Fetch ;
3332import javax .persistence .criteria .From ;
34- import javax .persistence .criteria .Join ;
3533import javax .persistence .criteria .Path ;
3634import javax .persistence .criteria .Predicate ;
35+ import javax .persistence .metamodel .EntityType ;
36+ import javax .persistence .metamodel .PluralAttribute ;
3737
3838import com .introproventures .graphql .jpa .query .schema .impl .PredicateFilter .Criteria ;
3939import graphql .language .NullValue ;
@@ -416,17 +416,17 @@ else if (type.equals(UUID.class)) {
416416 }
417417 else if (Collection .class .isAssignableFrom (type )) {
418418 // collection join for plural attributes
419- // TODO need better detection
420- if ( field .getModel () == null ) {
421- Join <?,?> join = null ;
419+ if ( PluralAttribute . class . isInstance ( from . getModel ())
420+ || EntityType . class . isInstance ( from .getModel ()) ) {
421+ From <?,?> join = null ;
422422
423423 for (Fetch <?,?> fetch : from .getFetches ()) {
424424 if (fetch .getAttribute ().getName ().equals (filter .getField ()))
425- join = (Join <?,?>) fetch ;
425+ join = (From <?,?>) fetch ;
426426 }
427427
428428 if (join == null ) {
429- join = (Join <?,?>) from .fetch (filter .getField ());
429+ join = (From <?,?>) from .fetch (filter .getField ());
430430 }
431431
432432 Predicate in = join .in (value );
@@ -446,7 +446,7 @@ else if (Object.class.isAssignableFrom(type)) {
446446 else {
447447 Object object = value ;
448448
449- if (List .class .isInstance (value )) {
449+ if (Collection .class .isInstance (value )) {
450450 object = getValues (object , type );
451451 } else {
452452 object = getValue (object , type );
@@ -468,8 +468,8 @@ else if (filter.getCriterias().contains(PredicateFilter.Criteria.IN)
468468 ) {
469469 CriteriaBuilder .In <Object > in = cb .in (from .get (filter .getField ()));
470470
471- if (List .class .isInstance (object )) {
472- List .class .cast (object )
471+ if (Collection .class .isInstance (object )) {
472+ Collection .class .cast (object )
473473 .forEach (in ::value );
474474 } else {
475475 in .value (object );
@@ -502,9 +502,9 @@ private Object getValue(Object object, Class<?> type) {
502502 }
503503
504504 private Object getValues (Object object , Class <?> type ) {
505- List <Object > objects = new ArrayList <>();
505+ Collection <Object > objects = new ArrayList <>();
506506
507- for (Object value : List .class .cast (object ).toArray ()) {
507+ for (Object value : Collection .class .cast (object ).toArray ()) {
508508 objects .add (getValue (value , type ));
509509 }
510510
0 commit comments