Setup for callback module
==================

private Dao infoData = null;  //  defined in spring
DetailCallback callBack = new DetailCallback("function1");
infoData.getInfoData(searchKey, callBack);
Set<DataStored> dataStored = callBack.getDataStored();

Calling callback module
==================

public abstract class Prototype implements java.io.Serializable {
   
    private static final long serialVersionUID = 1L;
}

public interface Dao {
public List getInfoData(Long searchKey, ResultCallback callback);
}

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class hibernateCall  implements Dao {
    protected final Log log = LogFactory.getLog(getClass());

    private String className = null;     //  defined in spring.  see below
    private Class<?> classE;
    private CriteriaBuilder criteriaBuilder;  // defined in spring.  see below

    public void setClassName(String className) {
        this.className = className;
        try {
            this.classE = Class.forName(className);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public String getclassName() {
        return entityclassName;
    }

    public Class<?> getClassC() {
        return classE;
    }

    /** default constructor */
    public DaoHibernate() {
    }

    public void save(Prototype obj) {
        getHibernateTemplate().saveOrUpdate(obj);
    }

    public void delete(Prototype obj) {
        getHibernateTemplate().delete(obj);
    }

        
    public List getInfoData(Long searchKey, ResultCallback callback) {
        return (List) getHibernateTemplate().execute(getDataCallBack(caseId, callback));
    }
    
    
    
       //~ Callback
    private HibernateCallback getDataCallBack(final Long searchKey, final ResultCallback resultCallback) {
        return new HibernateCallback() {
            public List doInHibernate(Session session) throws HibernateException {
                List results = null;
                try
                {
                    Criteria criteria = session.createCriteria(entityClass);
                    criteria.add(Restrictions.eq("searchKey",searchKey));
                    
                    results = criteria.list();
                    
                    if ((results == null) || (results.size() == 0))
                            return null;
                    int noOfResponses = results.size();
                    for (int ii = 0; ii<noOfResponses; ii++)
                    {
                        Prototype prototype = (Prototype) results.get(ii);
                        resultCallback.execute(prototype);
                    }
                }
                catch (Exception e)
                {
                    log.error("Error getting data" + searchKey + "::" +  e);
                    results = null;
                }
                
                return results;
            }   
        };
    }
}


CallBack method module
===================

public class DetailCallback implements ResultCallback {
    
  private DataStored [] dataStored = null;
  private String type = null;
    
  public DetailCallback(String type) {
                   this.type = type;
                   this.dataStored = new HashSet<DataStored>();
    }
    
    public void execute(Prototype prototype) {
        
            try {
                getData(prototype);
            } catch (Exception e) {
                log.error("Error in getData--", e);
            }
        
        
    }

    private void getData(Prototype prototype) {
        
        DataStored dataStoredOne = new DataStoredOne();
        
        DataBaseTable databaseTable = (DataBaseTable) prototype;
       
       dataStoredOne.setId(databaseTable.getId);

       [retrieve and store other data from different but related database tables]
            
        addDataStored(dataStoredOne);        

        
    }

    
    public void addDataSored(DataStored dataStoredOne) {
        dataStored.add(dataStoredOne);
    }
    
    public Set<DataStored> getDataStoredSet() {
        return dataStored;
    }
     
    
}

Hibernate definitions and classes
======================

public class DataBaseTable extends Prototype  {

    private static final long serialVersionUID = 1L;


    private Long searchId;
    private Set<Info> infoDataDS = new HashSet<Name>(0);

    public DataBaseTable() {
        super();
    }

   
    public DataBaseTable(Long searchId,
            Set<Info> infoDataDS) {
            this.searchId = searchId;
             this.infoDataDS = infoDataDS
             
    }

    public Set<Info> getInfo() {
        return this.infoData;
    }

    public void setInfo(Set<Info> infoData) {
        this.infoData = infoData;
    }

   

XML definitions

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 18, 2008 4:07:00 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="path.DatabaseTable" table="DATA_BASE_TABLE">
        <id name="id" type="long">
            <column name="SEARCH_ID" precision="22" scale="0" />
            <generator class="sequence">
                <param name="sequence">SEARCH_ID_SEQ</param>
            </generator>
        </id>
      
        <set name="infoDataDS" inverse="true" cascade="all" >
            <key>
                <column name="INFO_DATA_DS_ID" precision="22" scale="0" />
            </key>
            <one-to-many class="path.Info" />
        </set>
    </class>
</hibernate-mapping>

Spring definitions --
==============

    <bean id="hibernateCall" parent="hibernateDao">
        <property name="className"><value>hibernate.database.name</value></property>               
    </bean>

    <bean id="hibernateDao" class="classPath.DaoHibernate">
        <property name="hibernateTemplate"><ref local="hibernateTemplate"/></property>
        <property name="criteriaBuilder"><ref bean="criteriaBuilder"/></property>
    </bean>
   
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
   </bean>

        <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <description>Hibernate session factory.</description>
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingDirectoryLocations">
            <list>
                <value>classpath:/path/prototype</value>
                        </list>               
            </property>

        <property name="hibernateProperties">
           <props>
             <prop                                                 key="hibernate.dialect">org.hibernate.dialect.OracleDialect
                     </prop>
              <prop key="hibernate.show_sql">false</prop>                
             <prop                      key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider
                     </prop>            
           </props>
        </property>
    </bean>

    <bean id="dataSource" autowire="byName" parent="jndiDataSource">
        <property name="jndiName" ref="jndiName"/>
    </bean>

    <bean id="jndiDataSource" abstract="true" class="org.springframework.jndi.JndiObjectFactoryBean">
        <description>Bean  retreives a datasource object via JNDI lookup.</description>
    </bean>

<bean id="jndiName" class="java.lang.String">
                                        <constructor-arg type="java.lang.String" value="java:/jdbc/db"/></bean>

 

Database xml file
============
<datasources>
<local-tx-datasource>
    <jndi-name>jdbc/db</jndi-name>
    <connection-url>jdbc:oracle:thin:@100.100.100.100:1521:DatabaseName</connection-url>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <prepared-statement-cache-size>40</prepared-statement-cache-size>
    <min-pool-size>25</min-pool-size>
    <max-pool-size>65</max-pool-size>
    <max-idle-timeout>800</max-idle-timeout>
    <blocking-timeout-millis>20000</blocking-timeout-millis>
    <idle-timeout-minutes>10</idle-timeout-minutes>
   <security-domain>PasswordEncrypted</security-domain>
  </local-tx-datasource>
<datasources>