hi,
from javadoc of HibernateCursorItemReader<T> :
"When stateful session is used it will be cleared after successful commit without being flushed (no inserts or updates are expected)."
the commit above mean the commit-interval's commit (chunk comit)? or hibernate database transaction commit ? if is the chunk commit, mean the session only store small amount of object in memory and will clear on commit-interval right? so we no need to worry the session in overload until throws exception.
Due to the stateful session in reader can't obtain by ItemProcessor and Writer, I wondering in future will spring batch eventually support a common template in hibernate world like code below, which is possible to do in chunk oriented:
all the code above will be bound to same database transaction (hence we can process the object without worry about the session.)Code:// this code for item reader, like current implementation. Session session = sessionFactory.getCurrentSession(); String SELECT = "from User"; session.setCacheMode(CacheMode.IGNORE); session.setFlushMode(FlushMode.MANUAL); ScrollableResults cursor = session.createQuery(SELECT).scroll(ScrollMode.FORWARD_ONLY); //the code here in Item processor //doing whatever on User object, e.g delete. insert, update. //the code here is in writer. //log the object.. etc //this code maybe in infrastructure if ( ++count % 50 == 0 ) { session.flush(); session.clear(); } cursor.close();
this scenario is quite useful (at least to me) which involve the stateful session, like:
1) iterate the user, get the notification criterion and notify user.
2) delete inactive user
and etc which can take advantages of batch processing (retry, restart etc).
any idea ?
happy hacking
--------------
kiwi


) which involve the stateful session, like:
Reply With Quote