-->
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: What's wrong with this pice of code?
PostPosted: Mon Jun 07, 2004 1:55 am 
Beginner
Beginner

Joined: Tue Mar 30, 2004 5:54 am
Posts: 22
Location: Bangalore
It is a simple procedure which returns budget value with a small query ...

So ... I have it as ... it is part of the domain layer.
Code:
public double getBudgetAmount() {
        Session session = HibernateUtil.getSession();
        String orgCode = organisation.getOrgCode();
        String elementId = costElement.getElementID();
        String quarter = null;
        budgetAmount = 0;
        if (budgetYear.getMonth() <= 3) {
            quarter = "Q1";
        } else if (budgetYear.getMonth() <= 6) {
            quarter = "Q2";
        } else if (budgetYear.getMonth() <= 9) {
            quarter = "Q3";
        } else {
            quarter = "Q4";
        }
        Logger sfLogger = Logger.getLogger(LaborItem.class.getName());
       
       try {
            Iterator i = session.iterate(" select sum(labor.laborCost) from LaborItem as labor where labor.budgetType = 'NL' and labor.costType = 'P' " +
                    " and  labor.quarter = :quarter " +
                    " and  labor.organisation.orgCode = :orgCode " +
                    " and  labor.costElement.elementID = :elementId " +
                    "   ", new Object[] {quarter, orgCode, elementId} , new Type[] {Hibernate.STRING, Hibernate.STRING, Hibernate.STRING});
            while (i.hasNext()) {
                budgetAmount = ((Double) (i.next()) ).doubleValue() ;
            }
        } catch (HibernateException ex) {
            sfLogger.log(Level.SEVERE, "retriving budgeted amount failed.", ex);
            ex.printStackTrace();
        } finally {
           try {
               session.close();
           } catch (HibernateException ex) {
               ex.printStackTrace();
               sfLogger.log(Level.SEVERE, "closing session failed", ex);
               throw new RuntimeException("closing session failed", ex);
           }
    }       
      return budgetAmount;
   }


I am calling this procedure within a loop(from application layer) ... the first loop complets successfully in the next loop I am getting NullpointerException.

BTW ... I do have one Session opened in the calling program ... could this be the problem?

I am using hibernate 2.1, orcale 9i.

Please help.

Thanks

_________________
Thanks
Irfani


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 4:24 am 
Beginner
Beginner

Joined: Tue Mar 30, 2004 5:54 am
Posts: 22
Location: Bangalore
Well I got the answer ... thanks for those who tried ...

Actually the sum aggregate function in select is returning null, which in-turn is causing the problem ... so here is the solution.

Code:
            Iterator i = session.iterate(" select sum(labor.laborCost) from LaborItem as labor where labor.budgetType = 'NL' and labor.costType = 'P' " +
                    " and  labor.quarter = :quarter " +
                    " and  labor.organisation.orgCode = :orgCode " +
                    " and  labor.costElement.elementID = :elementId " +
                    "   ", new Object[] {quarter, orgCode, elementId} , new Type[] {Hibernate.STRING, Hibernate.STRING, Hibernate.STRING});
           while (i.hasNext()) {
               Object ba = i.next();
               budgetAmount = ( ba != null ? ((Double) ba ).doubleValue() : 0);
            }

_________________
Thanks
Irfani


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.