Step2. Configure applicationContext-hibernate.xml in the spring framework. ..... <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> ..... <prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> ... </bean>
Step3. Configure the hibernate mapping file(ie. *.hbm.xml), add a new attribute: <cache usage="read-only"/>
Step 4. Change the dao. Before it retireves data, it will be asked to use cache, for example: getHibernateTemplate().setCacheQueries(true); or query.setCacheable(true)
Now, everything looks very good. It only need less than 1 second to get all the data. Much faster than before.