| Hi All,I have a DAO method written to fetch a list of records based on certain search criteria's. The table mapped to the entity has lot of records and also keeps growing at a faster rate. I use the below  method to get all the records satisfying some basic search criterias and show their property values in a  'pdf' or 'excel' . The method is,
 
 @SuppressWarnings("unchecked")
 public List<EntityAuditRecord> fetchEntityAuditRecords(Map<String, Object> searchCriteria) {
 
 Criteria criteria = getSession().createCriteria(EntityAuditRecord.class);
 Boolean flag = Boolean.FALSE;
 
 if ((searchCriteria != null) && !(searchCriteria.isEmpty())) {
 
 if (searchCriteria.containsKey("userId")) {
 criteria = criteria.add(Restrictions.eq("userId", searchCriteria.get("userId")));
 flag = Boolean.TRUE;
 }
 
 if (searchCriteria.containsKey("eventTypeCode")) {
 criteria = criteria.add(Restrictions.eq("eventTypeCode", searchCriteria.get("eventTypeCode")));
 flag = Boolean.TRUE;
 }
 
 if (searchCriteria.containsKey("outcomeCode")) {
 criteria = criteria.add(Restrictions.eq("outcomeCode", searchCriteria.get("outcomeCode")));
 flag = Boolean.TRUE;
 }
 
 if (searchCriteria.containsKey("applicationName")) {
 criteria = criteria.add(Restrictions.eq("applicationName", searchCriteria.get("applicationName")));
 flag = Boolean.TRUE;
 }
 
 if (searchCriteria.containsKey("beginDate")) {
 criteria = criteria.add(Restrictions.ge("auditDate", searchCriteria.get("beginDate")));
 flag = Boolean.TRUE;
 }
 
 if (searchCriteria.containsKey("endDate")) {
 criteria = criteria.add(Restrictions.le("auditDate", searchCriteria.get("endDate")));
 flag = Boolean.TRUE;
 }
 
 if (searchCriteria.containsKey("orgId")) {
 criteria = criteria.add(Restrictions.eq("orgId", searchCriteria.get("orgId")));
 flag = Boolean.TRUE;
 }
 
 if (searchCriteria.containsKey("action")) {
 criteria = criteria.add(Restrictions.ilike("action", (String) searchCriteria.get("action"), MatchMode.ANYWHERE));
 flag = Boolean.TRUE;
 }
 
 if (searchCriteria.containsKey("roleId")) {
 criteria = criteria.add(Restrictions.eq("roleId", searchCriteria.get("roleId")));
 flag = Boolean.TRUE;
 }
 
 }
 
 if (flag) {
 return criteria.list();
 } else {
 return Collections.EMPTY_LIST;
 }
 
 }
 
 
 I get java heap space out of memory error due to the large volume of data being fetched, and which is understandable. I had a look at the scrollable result set option but I am not sure whether that would help my cause because the 'pdf' creation code is at a servlet level and it does have access to a hibernate session to clear/flush the session cache after processig a few records instead of me getting all the records in a list and sending it to the 'pdf' creation class.We use 'OpenSessionInViewInterceptor' to deal with the session creation/closing  process and this code does not have access to the hibernate session . I might be wrong. Any hint would be helpful?
 
 this is what we have configured,
 <bean id="openSessionInViewInterceptor"
 class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
 <property name="sessionFactory" ref="sessionFactory" />
 <property name="singleSession" value="true" />
 <property name="flushModeName" value="FLUSH_AUTO" />
 </bean>
 
 regards
 Aravias
 
 
 |