Hi,
Code:
DetachedCriteria c1 = DetachedCriteria.forClass(Person.class).setProjection(Projections.property(Person.ID));
c1.add(Restrictions.in(Person.ID, event.getAclPersonIds()));
DetachedCriteria c2 = DetachedCriteria.forClass(Project.class).setProjection(Projections.property(Project.ID));
c2.add(Restrictions.in(Project.ID, event.getAclProjectIds()));
criteria.add(Restrictions.or(Subqueries.in(TimeReport.PERSON, c1), Subqueries.in(TimeReport.PROJECT, c2)));
quick help:
- many-to-one - TimeReport-to-Person - TimeReport.PERSON
- many-to-one - TimeReport-to-Project - TimeReport.PROJECT
- ID as entity id in all classes.
gives...
# org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:318)
# org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:56)
# org.hibernate.criterion.LogicalExpression.toSqlString(LogicalExpression.java:39)
# org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
# org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
# org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:68)
# org.hibernate.impl.SessionImpl.list(SessionImpl.java:1543)
# org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
Adding projections to c1 and c2 don't help much as I don't see way to add property to Subqueries.in() side.
What I am trying to achieve is
select *
from timereport
where (project_id in (<AclProjectIds>) or person_id in (<AclPersonIds>))
or at least...
select *
from timereport
left join person on timereport.person_id = person.id
left join project on timereport.project_id = project.id
where (project.id in (<AclProjectIds>) or person.id in (<AclPersonIds>))
Any ideas?