From documentation
If we have a case where we need to insert 1000 000 rows/objects:
Session session = sessionFactory.openSession();
Transaction tx =
Stateless Session has an advantage over Session in terms of performance because stateless session will skip the transaction commit to session or session flush methods used in Session object. However, it is important to note that the service/DAO should NOT try to perform in-session data manipulation to either parent or any child object. It will throw exception. Also, make sure to close the session explicitly otherwise one will end up with leaked connections.
To gain more performance with Stateless session, if one is using Spring driven transaction, mark the Spring transaction as read only and set the propagation required as NEVER.
But again, do not try this where one has to manipulate the object model.
@Transactional(value="someTxnManager", readOnly=true, propagation=Propagation.NEVER)
public List get(...) {
return daoSupport.get(...);
}
in daoSupport
StatelessSession session = sessionFactory.openStatelessSession();
try{
// do all operations here
}
...
...
finally{
session.close();
}