-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: criteria query, disjunction() or or() and Subqueries.in()
PostPosted: Thu Nov 16, 2006 4:34 pm 
Newbie

Joined: Thu Nov 16, 2006 3:53 pm
Posts: 2
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?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 4:41 pm 
Newbie

Joined: Thu Nov 16, 2006 3:53 pm
Posts: 2
... and hibernate is the one with jboss.4.0.4.GA - 3.2.0.cr2


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.