Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2006-2007 the original author or authors.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.springframework.batch.item.database;
 import java.util.Map;
org.springframework.batch.item.ItemReader for reading database records built on top of Hibernate and reading only up to a fixed number of items at a time. It executes an HQL query when initialized is paged as the method is called. The query can be set directly using setQueryString(java.lang.String), a named query can be used by setQueryName(java.lang.String), or a query provider strategy can be supplied via setQueryProvider(org.springframework.batch.item.database.orm.HibernateQueryProvider).

The reader can be configured to use either org.hibernate.StatelessSession sufficient for simple mappings without the need to cascade to associated objects or standard hibernate org.hibernate.Session for more advanced mappings or when caching is desired. When stateful session is used it will be cleared in the method without being flushed (no data modifications are expected).

The implementation is thread-safe in between calls to, but remember to use saveState=false if used in a multi-threaded client (no restart available).

Dave Syer
 public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> implements ItemStreamInitializingBean {
 	private int fetchSize;

The parameter values to apply to a query (map of name:value).

parameterValues the parameter values to set
 	public void setParameterValues(Map<StringObjectparameterValues) {
 		this. = parameterValues;

A query name for an externalized query. Either this or the { query string or the { query provider should be set.

queryName name of a hibernate named query
 	public void setQueryName(String queryName) {

Fetch size used internally by Hibernate to limit amount of data fetched from database per round trip.

fetchSize the fetch size to pass down to Hibernate
	public void setFetchSize(int fetchSize) {
		this. = fetchSize;

A query provider. Either this or the {{@link setQueryString(java.lang.String) query string} or the {{@link setQueryName(java.lang.String) query name} should be set.

queryProvider Hibernate query provider
	public void setQueryProvider(HibernateQueryProvider queryProvider) {

A query string in HQL. Either this or the { query provider or the { query name should be set.

queryString HQL query string
	public void setQueryString(String queryString) {

The Hibernate SessionFactory to use the create a session.

sessionFactory the org.hibernate.SessionFactory to set
	public void setSessionFactory(SessionFactory sessionFactory) {

Can be set only in uninitialized state.

useStatelessSession true to use org.hibernate.StatelessSession false to use standard hibernate org.hibernate.Session
	public void setUseStatelessSession(boolean useStatelessSession) {
	public void afterPropertiesSet() throws Exception {
		Assert.state( >= 0, "fetchSize must not be negative");
	protected void doOpen() throws Exception {
	protected void doReadPage() {
		if ( == null) {
		else {
	protected void doJumpToPage(int itemIndex) {
	protected void doClose() throws Exception {
New to GrepCode? Check out our FAQ X