-->
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: Can rowCount()/uniqueResult() return null ?
PostPosted: Mon Oct 29, 2007 10:17 am 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
Hi!

I use Hibernate version 3.2.0cr2.

Can it happen that the uniqueResult() method returns null in the following code ?

Code:
protected static int rowCount(Criteria crit) {
    crit.setProjection(Projections.rowCount());
    return (Integer) crit.uniqueResult();
}


If the criteria matches zero rows, then after the projection it should return an Integer value of zero, right ?

I ask because in some cases it returns null (and by that causes a null pointer exception) in our application.

Thanks and regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 30, 2007 1:05 pm 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
The only relevant doc I could find was JSR-220-persistence and in section 4.8.4 it says that for COUNT the return type is Long and in case of no objects it returns zero.

That does not match our case (return type is Integer and it sometimes returns null) :-(

Can anyone sched some light on this ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 5:27 pm 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
ah, found it.

We use two (and more...) session factory's.
Due to some changes in some related code the factories get mixed up.
So class C was mapped in factory 1 , but not in factory 2.
Factory 1 should be used, but in some cases we used factory 2 by mistake.

For get() methods it throwed "MappingException: Unknown entity C",
but createCriteria(C.class).list() just returns null, no exception.
Same if we add a projection to it.


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.