-->
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.  [ 3 posts ] 
Author Message
 Post subject: simple subquery in criteria api nullpointer
PostPosted: Mon Jun 14, 2010 1:00 pm 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
I am getting this nullpointer When I add a simple subquery. Am I doing something wrong or is this a bug?

Code:
java.lang.NullPointerException
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:341)
   at org.hibernate.criterion.SubqueryExpression.createAndSetInnerQuery(SubqueryExpression.java:136)
   at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:71)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:357)
   at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:102)
   at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
   at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:91)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1577)


Code:
         DetachedCriteria subquery = DetachedCriteria.forClass(Wtns.class, "wtns");
         subquery.add(Restrictions.eq("productid", "303"));         
                  //Restrictions.like("wtns.pk.wtn", ident)
         
         SimpleExpression btn = Restrictions.like("trans."+BY_BTN.code, ident);
         Criterion wtns = Property.forName("trans.tpvid").in(subquery);
         LogicalExpression exp = Restrictions.or(btn, wtns);
         
         criteria.add(wtns);


If I change the last line from criteria.add(wtns) to criteria.add(btn), everything works fine. My goal is to be using the criteria.add(exp) but I can't seem to get that working.

thanks,
Dean

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


Top
 Profile  
 
 Post subject: Re: simple subquery in criteria api nullpointer
PostPosted: Tue Jun 15, 2010 4:09 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
I'm pretty sure that's caused by not setting a projection on your subquery

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject: Re: simple subquery in criteria api nullpointer
PostPosted: Tue Jun 15, 2010 11:35 pm 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
thanks, that did the trick...duh, it was not returning a list of the type I needed, just the entities which I didn't want but didn't think about that. Wish the error was a bit better than the cryptic nullpointer but oh well.

thanks!
Dean

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.