To get even better performance results, you can enable jdbc batch instructions in SessionFactory / EntityManager by setting the hibernate.jdbc.batch_size property in the SessionFactory configuration (i.e. LocalEntityManagerFactoryBean ).
To have the best advantage for inserting / updating a jdbc batch, write as many objects of the same type as possible. Hibernate will detect when you write another type of entity, and will automatically clear the package, even if it has not reached a certain lot size.
Using StatelessSession behaves basically the same as using Spring JdbcTemplate . The advantage of using StatelessSession is that SQL matching and translation is handled by Hibernate. When you use my StatelessSessionFactoryBean , you can only mix Session and StatelessSession in one transaction. But be careful with modifying the Entity loaded by Session and storing it with StatelessSession , because this will lead to locking issues.
Willem dekker
source share