View Single Post
  #7 (permalink)  
Old 09-01-2008, 03:36 PM
mathes_n mathes_n is offline
Member
 
Join Date: Aug 2008
Posts: 4
mathes_n is on a distinguished road
Thanks for your suggestion but even after splitting it gives the same result

My splitted code looks like

public List retrieveCustomersForSearch() throws Exception{
List customers = null;
//List tempList = null;
Session session = null;
CustomerBean customerBean = null;
Object[] resultArray = null;
try {
session = HibernateUtil.currentSession();
/*customers = session.createSQLQuery("SELECT name,customer_id FROM CUSTOMERS order by name")
.addEntity("customers", com.boeing.tsas.castle.model.CustomerBean.class).l ist();*/

String SQLQuery = "SELECT name,customer_id FROM CUSTOMERS order by name";
List tempList = session.createSQLQuery(SQLQuery)
.addScalar("customer_id", Hibernate.LONG)
.addScalar("name", Hibernate.STRING)
.list();

tempList = tempList==null?new ArrayList():tempList;
customers = customerBeanForm(tempList);
} catch (HibernateException he) {
log.error("caught: " + he);
throw new PersistenceException(he.getMessage(), he);
} catch (Exception e) {
e.printStackTrace();
e.getMessage();
throw new RuntimeException("Unable to retrive Customers from datastore: ", e);
}
return customers;
}


private List customerBeanForm(List tempList){
List customers = new ArrayList();
//Session session = null;
CustomerBean customerBean = null;
int size;
if (tempList != null && tempList.size() >0) {
size = tempList.size();
Object[] resultArray = null;
for (int index = 0; index < size; index++) {
//System.out.println("Inside before obj array ::"+new java.text.SimpleDateFormat("hh:mm:ss:SSS").format( new Date()));
resultArray = (Object[]) tempList.get(index);
//System.out.println("Inside After obj array ::"+new java.text.SimpleDateFormat("hh:mm:ss:SSS").format( new Date()));
customerBean = new CustomerBean();
customerBean.setCustomerId(Long.valueOf(resultArra y[0].toString()));
if(resultArray[1]!= null) {
customerBean.setName(resultArray[1].toString());
}else {
customerBean.setName(null);
}

customers.add(customerBean);
//System.out.println("last line in for ::"+new java.text.SimpleDateFormat("hh:mm:ss:SSS").format( new Date()));
}
}
return customers;
}
Reply With Quote