-->
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: NullPointerException when using criteria with projection
PostPosted: Tue Jul 25, 2006 10:23 am 
Newbie

Joined: Fri Jun 30, 2006 11:44 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.0cr2

Mapping documents:
using annotation mapping

Code between sessionFactory.openSession() and session.close():
Code:
            DetachedCriteria dc = DetachedCriteria.forClass(Debt.class);
            dc.add(Restrictions.eq("client", getClient()));
            Criterion crit = Property.forName("debt").in(dc);
           
            DetachedCriteria countCrit = DetachedCriteria.forClass(Case.class);
            countCrit.add(crit);
            countCrit.setProjection(Projections.rowCount());


            Integer rowCount = (Integer) getHibernateTemplate()
                .findByCriteria(countCrit).get(0);


Full stack trace of any exception that occurs:
java.lang.NullPointerException
at
# org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:318)
# org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:56)
# org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
# org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:71)
# 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)
# org.springframework.orm.hibernate3.HibernateTemplate$37.doInHibernate(HibernateTemplate.java:988)
# org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
# org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:978)
# org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:971)
# my.dao.DaoImpl.count(DaoImpl.java:33)


So, the problem is that if i set projection to criteria that has a subquery then i get NPE from hibernate.
In SQL terms, i would like to see (select count(*) from case where case.debt_id in (select debt_id from debts where client_id = 1)), which should be rather simple query.

As far as i can see, CriteriaJoinWalker starts to assemble a query, asks outer criteria for its projection (which is count(*)) and then proceeds to ask subquery criteria for projection too, but subquery criteria projection is null (and as far as i can see, that's correct).

What i'm not sure about is the solution. I can't add projection to subquery, and besides, it wouldn't be correct to do so as far as i can see.
Am i assembling my criteria wrong? Mappings are correct and work, with or without projections.

Thank you for your time.

Tanel Unt


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Thu Aug 14, 2008 2:32 pm 
Newbie

Joined: Thu Aug 14, 2008 2:28 pm
Posts: 1
I was wondering if anyone has found a solution or workaround for this problem. I am also getting the same thing when I try to use projections.


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.