• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Caused by: org.hibernate.SessionException: Session is closed! at org.hibernate.impl.AbstractSession

 
Arati Satyappanavar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , please any one can help me on the follwoing error

I am randomly sometimes getting session closed error eventhough i have not closed explicitely

my ServicesImpl code

@SuppressWarnings("unchecked")
@Override
public List<CFinancialYear> getFinancialYrsForBudgetCreation() throws SQLException, BudgetFailedException, ParseException {
List<Budgets> bList=getBudgetsDAO().getActiveBudgets();
if(bList!=null && bList.size()>0){//active budget exists
return this.session.createCriteria(CFinancialYear.class).add(Restrictions.eq("id", bList.get(0).getFinYearId())).list();
}else{
//check for latest approve budget and get financialyear
Budgets b=getBudgetsDAO().getRecentlyApprovedBudget();
if(b!=null){// approved budget exists
return getNextFinancialYear(b.getFinYearId());
}else{//reading financialyear from egf_config and retrieving financial year
return this.session.createCriteria(CFinancialYear.class).add(Restrictions.eq("finYearRange", getBudgetStartYear())).list();
}
}
}


and DAO code

@SuppressWarnings("unchecked")
public List<Budgets> getActiveBudgets(){
System.out.println("this.getSession().isOpen()"+this.getSession().isOpen());
MstrBudgetStatus activeStatus=getMstrBudgetStatusDAO().getBudgetActiveStatus();
return HibernateUtil.getCurrentSession().createCriteria(Budgets.class).add(Restrictions.eq("mstrBudgetStatus", activeStatus)).list();
//return this.getSession().createCriteria(Budgets.class).add(Restrictions.eq("mstrBudgetStatus", activeStatus)).list();

}


Caused by: org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.createCriteria(SessionImpl.java:1508)
at mrc.gov.in.budget.dao.BudgetsDAO.getActiveBudgets(Unknown Source)
at mrc.gov.in.budget.api.BudgetServicesImpl.getFinancialYrsForBudgetCreation(Unknown Source)
at mrc.gov.in.budget.client.action.BudgetDetailsAction.loadFormForCreate(Unknown Source)
at sun.reflect.GeneratedMethodAccessor779.invoke(Unknown Source)

please help me on this.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arati Satyappanavar wrote:Hi , please any one can help me on the follwoing error

I am randomly sometimes getting session closed error eventhough i have not closed explicitely

Have you opened the session explicitly? I have had little work with hibernate, but if I recall:
1) If you don't explicitly open a session, one may be opened with the transaction, in which case it also gets closed with the transaction.
2) You get the same error if you try to use a session which hasn't yet been opened (i.e. trying to use the current session without first explicitly creating a session through the session manager (or factory or whatever it is called)

Have you looked to see what other reasons a session might close on you? Do they close if there has been long inactivity (timeout)? Is it configurable?
 
Anil Sable
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


For the mapping file of following class

CFinancialYear
Budgets

add lazy="false" to the association element like one-to-one, one-to-may, many-to-one, many-to-many

this error occur when you retrieved object from database, its all primitive elements like integer, string, Boolean are retrieved but all other element like relations, composition cannot retrieved to archive performance. to resolve it add above statement in your association element
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic