Spring Data - QueryDSL InnerJoin predicate -
lets assume have following domain objects (partially complete reduce code).
public class student { @onetomany(mappedby="student") list<assignment> assignments; } public class assignment { @manytoone student student; @onetoone implementation implementation; } public class implementation { @onetoone assignment assignment; @onetomany(mappedby="implementation") list<assessment> assessments; } public class assessment { @manytoone implementation implementation; string grade; }
so query want perform "select students assignment implementation has been performed (not null) , has not been assessed @ (list<assessment>#isempty()
)
so i'm using querydsl
, try use following query students non-implemented assignments
public class myservice { @autowired private studentrepository studentrepository; public iterable<student> foo() { return studentrepository.findall( qstudent.student.assignments.any().implementation.isnotnull() ); } }
and above query seems ignored.
then use following combination (implemented exercises , empty assessments
)
studentrepository.findall( qstudent.student.assignments.any().implementation.isnotnull() .and(qstudent.student.assignments.any().implementation.assessments.isempty()) );
again makes no differences. idea i'm doing wrong
have tried this:
qassignment assignment = qassignment.assignment; listsubquery<assignment> subquery = new jpasubquery().from(assignment) .where(assignment.implementation.isnotnull())) .and(assignment.implementation.assessments.isempty()) .list(assignment); studentrepository.findall( qstudent.student.assignments.contains(subquery) );
i'm not sure why code not working, guess it's because any()
subquery exists shortcut. see https://stackoverflow.com/a/25453708/2672352
Comments
Post a Comment