-->
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: scalar query using max() not working
PostPosted: Tue Nov 04, 2003 12:52 pm 
Newbie

Joined: Tue Nov 04, 2003 12:41 pm
Posts: 6
Hi,

I want to retrieve the max value for a column and I followed the example code for scalar queries except for the (Object []) cast, I got a classCast exception without it. Now I am getting a null pointer exception. The message "Wierd. row is null" gets printed. I tried to run it with and without valid data in the DB. In one case "Wierd. retVal is null." gets printed. Source code:

Code:

private int getLastDataRecNum(int feedId)
   throws HibernateException
{
   String qryString =
            "select max(ord.DataRecNumInFile) from myPackage.ASIOrder ord where ord.ASIFeedId = " + feedId;

   Transaction transaction = _session.beginTransaction();
   Iterator result = _session.iterate(qryString);
   transaction.commit();

   if (result.hasNext()) {
       Object[] row = (Object []) result.next();
       if (row == null) {
          System.out.println("Wierd. row is null.");
          return -1;
       }
       Integer retVal = (Integer) row[0];
       if (lastDataRecNum == null) {
          System.out.println("Wierd. retVal is null.");
          return -1;
       }
       return retVal.intValue();
   }
   return -1;
}



Regards,
Vaishali

Code:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 11:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Strange, I would say that the iterator is filled with Long objects (and it is when I try it). This request does not return Tuple.

I'd rather use find() in this case, but the result is the same.

_________________
Emmanuel


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.