From: Juergen H. <ju...@in...> - 2006-03-28 20:06:30
|
Why couldn't you use HibernateTransactionManager in combination with = such data access code based on HibernateTemplate? HibernateTransactionManager doesn't do much more than open a Session, = start a transaction - and eventually commit the transaction and close the = Session. You can do any number of flush or clear calls inbetween... Of course, if there's anything specific we can offer in HibernateTransactionManager to better support such batch-style data = access, we are certainly open to it. Juergen =20 -----Original Message----- From: spr...@li... [mailto:spr...@li...] On Behalf = Of Meyer, Stefan Sent: Tuesday, March 28, 2006 12:57 PM To: spr...@li... Subject: [Springframework-developer] Batch processing with hibernate Hi, We need batch processing support for hibernate. The processing should = take place in one transaction and the list of processed entities must be = selected with "select ... For update". HibernateTransactionManager does not = support this. The reason is presumably that the first-level cache does not = support rollbacks. I think that it is possible nevertheless if you follow the following rules: 1. flush before setting a savepoint 2. clear the session before rolling back to a savepoint The consequences of the second point are usually not a problem in batch processing. Consider the recommended approach: -------------- hibernate.org Session session =3D sessionFactory.openSession(); Transaction tx =3D session.beginTransaction(); =20 ScrollableResults customers =3D session.getNamedQuery("GetCustomers") .setCacheMode(CacheMode.IGNORE) .scroll(ScrollMode.FORWARD_ONLY); int count=3D0; while ( customers.next() ) { Customer customer =3D (Customer) customers.get(0); customer.updateStuff(...); if ( ++count % 20 =3D=3D 0 ) { //flush a batch of updates and release memory: session.flush(); session.clear(); } } =20 tx.commit(); session.close(); ------------- Clearing the session after or before processing an entity returned from = the cursor will only result in slower performance when loading certain entities. We have implemented this kind of batch processing but support by hibernateTransactionManager would make our life a lot easier. -- Stefan Meyer Entwicklung s....@s2... T: +49.40.80 81 69-347 SinnerSchrader Neue Informatik >> Software. Design. Interfaces. http://www.s2neueinformatik.de/ =20 ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting = language that extends applications into web and mobile media. Attend the live = webcast and join the prime developer group breaking into this new coding = territory! http://sel.as-us.falkag.net/sel?cmd=3Dk&kid=110944&bid$1720&dat=121642 _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |