|
From: Meyer, S. <S....@S2...> - 2006-03-28 10:57:42
|
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 |