-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria et requête complexe
PostPosted: Thu Oct 05, 2006 4:06 pm 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Voici ma requête :

MMETHOD est associée à MCLASS via un champs parent_id.
MMETHOD est associée à TMETHOD via un champs target_id.

Select * from MCLASS WHERE class_id in (
Select parent_id from MMETHOD where method_id in (
Select target_id from TMETHOD where status = ? or status = ?
)
or method_id not in (
Select target_id from TMETHOD where target_id is not null
)
)

mon équivalent en Criteria :

Criteria criteria = SessionFactory.currentSession().createCriteria(MClass.class);

DetachedCriteria matchingMMethodsCriteria = DetachedCriteria.forClass(MMethod.class);

matchingMMethodsCriteria.setProjection(Projections.distinct(Projections.property("parent_id")));

DetachedCriteria matchingTMethodsCriteria = DetachedCriteria.forClass(TMethod.class);

matchingTMethodsCriteria.setProjection(Projections.distinct(Projections.property("target_id")));

DetachedCriteria linkedTMethodsCriteria = DetachedCriteria.forClass(TMethod.class);

linkedTMethodsCriteria.setProjection(Projections.distinct(Projections.property("target_id")));

Junction disjunction = Restrictions.disjunction();
boolean none = false;

for (STATUS o : status) {
disjunction.add(Restrictions.eq("status", o));
none = none || o == STATUS.NONE;
}

if (none) {
matchingMMethodsCriteria.add(
Restrictions.or(
Subqueries.propertyIn("primaryKey", matchingTMethodsCriteria.add(disjunction)),
Subqueries.propertyNotIn("primaryKey", linkedTMethodsCriteria)
)
);
}
else {
matchingMMethodsCriteria.add(Subqueries.propertyIn("primaryKey", matchingTMethodsCriteria.add(disjunction)));
}

criteria.add(Subqueries.propertyIn("primaryKey", matchingMMethodsCriteria));

et finalement l'exception suivante se produit a l'appel de 'list' sur criteria.

Caused by: java.lang.NullPointerException
at org.hibernate.criterion.SubqueryExpression.getTypedValues(SubqueryExpression.java:80)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters(CriteriaQueryTranslator.java:251)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:55)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:68)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1543)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)


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

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.