-->
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.  [ 1 post ] 
Author Message
 Post subject: Out of memory
PostPosted: Wed Aug 23, 2006 12:18 pm 
Newbie

Joined: Mon Jul 31, 2006 2:41 pm
Posts: 13
I'm new with Hibernate, and I was just hoping somebody could verify I'm using it efficiently. I'm getting an out of memory error after a while on my dev box using Jetty, and that hasn't happened before. Here is an example of the code that I believe may be causing it:





/**
* Load a list of these objects
*/
protected void loadList() throws LendingCrowdException
{
List triggerList = null;
HashMap tabDate = new HashMap();
HashMap tabs = new HashMap();
TriggerLeadList tList = new TriggerLeadList();
Session session = null;
String date = "";

try
{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();

//setup HQL where clause/order by criteria
Criteria criteria = session.createCriteria(TriggerLead.class);

//setup Calendar object
Calendar now = Calendar.getInstance();

tabDate.put(TODAY, now.getTime());

now.add(Calendar.DAY_OF_MONTH, -1);
tabDate.put(YESTERDAY, now.getTime());

now.add(Calendar.DAY_OF_MONTH, -1);
tabDate.put(TWO_DAYS_BACK, now.getTime());

now.add(Calendar.DAY_OF_MONTH, -1);
tabDate.put(THREE_DAYS_BACK, now.getTime());

/*
* This will setup the date to query based on the
* give days parameter passed in from webpage
*/
if(this.days <= 0)
{
switch (this.days)
{
case 0: criteria.add(Expression.ge(PULLDATE, tabDate.get(TODAY))); break;

case -1: criteria.add(Expression.ge(PULLDATE, tabDate.get(YESTERDAY)))
.add(Expression.lt(PULLDATE, tabDate.get(TODAY))); break;

case -2: criteria.add(Expression.ge(PULLDATE, tabDate.get(TWO_DAYS_BACK)))
.add(Expression.lt(PULLDATE, tabDate.get(YESTERDAY))); break;

case -3: criteria.add(Expression.ge(PULLDATE, tabDate.get(THREE_DAYS_BACK)))
.add(Expression.lt(PULLDATE, tabDate.get(TWO_DAYS_BACK))); break;

default: break;
}

if(StringUtils.isNotBlank(df.getString(TAB)))
{
if(df.getString(TAB).equals(NEW))
{
criteria.add(Expression.eq(STATUS_ID, new Integer(STATUS_NEW)));
}
else if(df.getString(TAB).equals(IN_PROGRESS))
{
criteria.add(Expression.eq(STATUS_ID, new Integer(STATUS_IN_PROGRESS)));
}
else if(df.getString(TAB).equals(CLOSED))
{
criteria.add(Expression.eq(STATUS_ID, new Integer(STATUS_CLOSED)));
}
else if(df.getString(TAB).equals(ARCHIVE))
{
criteria.add(Expression.eq(STATUS_ID, new Integer(STATUS_ARCHIVED)));
}
}
}


//if sorting and filtering have been specified, pass the
//criteria object off to our private filtering method
if (this.df.getString(FILTERING).equals(TRUE))
criteria = doFiltering(criteria, df);
else
criteria.addOrder(Order.asc(STATUS_ID));


/**
* Execute the hibernate query and iterate through results,
* creating a TriggerLeadList of TriggerLead objects. Also do a
* sloppy role check to make sure Scott Parrott has access to see all.
*/
if(this.assignedToId != SCOTT_PARROTT && this.assignedToId != JEFF_SHOEMAKER)
criteria.add(Expression.eq(ASSIGNED_TO, new Integer(this.assignedToId)));
triggerList = criteria.list();

for(int i=0; i<triggerList.size(); i++)
{
TriggerLead tl = (TriggerLead)triggerList.get(i);

//Get the status name from the statusId
Query query = session.createQuery(SQL.triggerLeadStatus);
query.setInteger(0, tl.getStatusId());
TriggerLeadStatus ts = (TriggerLeadStatus) query.list().get(0);
tl.setTriggerStatus(ts);

//Get the last calldate and calltime
query = session.createQuery(SQL.lastTriggerCallLog);
query.setParameter("tclid", new Integer(tl.getId()));
List tclList = query.list();

if(tclList.size() > 0)
{
TriggerCallLog tcl = (TriggerCallLog) tclList.get(0);
tl.setTriggerCallLog(tcl);

//Get the last result String from result_id
if(tcl != null)
{
query = session.createQuery(SQL.triggerLastResult);
query.setInteger(0, tcl.getResult_id());

TriggerLastResult tlr = (TriggerLastResult) query.list().get(0);
tl.setTriggerLastResult(tlr);
}
}

//Get the calls places today, and the total calls
Integer callsToday = (Integer) session.createSQLQuery(SQL.triggerCallsToday)
.addScalar(COUNT, Hibernate.INTEGER).setInteger(0, tl.getId()).uniqueResult();

Integer callsTotal = (Integer) session.createSQLQuery(SQL.triggerCallsTotal)
. addScalar(COUNT, Hibernate.INTEGER).setInteger(0, tl.getId()).uniqueResult();

tl.setCallsToday(callsToday.intValue());
tl.setCallsTotal(callsTotal.intValue());

tList.add(tl);
}

this.triggerleadList = tList;


}catch(Exception ex){
LendingCrowdLogger.log(LendingCrowdLevel.SEVERE, ex.toString(), ex);
}finally {
if (session != null) {
session.close();
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.