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