Hi there,
I have a table with ~140 000 rows and each records are relatively big.
So, I want to use a HibernateCursorItemReader to read them in chunk of 500.
My code is:
With this code, I get an OutOfMemory exception and I can say that the Reader(or Hibernate) is trying to read more than 500 rows because if I add a LIMIT of 500, it works.Code:<b:job id="copyFromHibernate" job-repository="jobRepository"> <b:step id="Step-1"> <b:tasklet transaction-manager="hibernateTransactionManager"> <b:chunk reader="myHibernateReader" writer="myWriter" commit-interval="500"/> </b:tasklet> </b:step> </b:job> <bean id="myHibernateReader" class="org.springframework.batch.item.database.HibernateCursorItemReader"> <property name="sessionFactory" ref="sessionFactory" /> <property name="useStatelessSession" value="true"/> <property name="fetchSize" value="500"/> <property name="queryString"> <value> <![CDATA[ FROM MyModel]]> </value> </property> </bean>
I tested with my own reader :
With this code, it works. I took a look at the code of HibernateCursorItemReader and it's more or less the same approach.Code:... @Override public MyModel read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { //sessionFactory is not ready in open(...)? if(session == null){ session = sessionFactory.openStatelessSession(); session.beginTransaction(); Query criteria = session.createQuery("FROM OccurrenceModel"); criteria.setFetchSize(500); iterator = criteria.scroll(ScrollMode.FORWARD_ONLY); } if(iterator.next()){ return (MyModel)iterator.get()[0]; } else{ return null; } }
The database is Postgresql and the TransactionManager is a hibernate4.HibernateTransactionManager.
Any idea what I'm doing wrong with the HibernateCursorItemReader?


Reply With Quote
