How to do select the data in batches using hibernate?

牧云@^-^@ 提交于 2019-12-01 12:46:51
user950415

In hibernate.properties, set the batch size using the parameter

hibernate.jdbc.batch_size= 'your_value'

To select data in a batch, you can apply data pagination by setting the initial position & the number of results to be fetched for a query.

for(int i=0; i < MAX_SIZE; i = i + BATCH_SIZE){

    List<Object> resultList = entityManager.createQuery(SQL_QUERY).setFirstResult(i).setMaxResults(BATCH_SIZE).getResultList();

    //-- Batch Computation
} 

I have provided sample code, can modify it accordingly.

To select the data with hibernate, in hibernate.properties, set the fetch size using the parameter:

hibernate.jdbc.fetch_size= SOME_VALUE

or in the query:

.setFetchSize(SOME_VALUE)

if you are updating data use: the batch_size

hibernate.jdbc.batch_size= SOME_VALUE
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!