Migrate HibernateTemplate and HibernateDaoSupport to the Hibernate Session

Proprietary

Spring Framework 7 removed HibernateTemplate and HibernateDaoSupport. This recipe rewrites getHibernateTemplate() calls that have a direct Session equivalent, such as get, save and delete, to use currentSession(), and adds @Transactional to the enclosing method, because the current session needs a transaction. A class that extends HibernateDaoSupport then gets its own SessionFactory field with setSessionFactory, getSessionFactory and currentSession methods in place of the base class, so existing XML or setter injection keeps working. That only happens when neither the class nor any of its subclasses still needs the rest of the HibernateDaoSupport API. Unlike HibernateTemplate, the Session doesn't translate exceptions to Spring's DataAccessException; annotate the DAO with @Repository to keep that. Everything else, such as find, execute or an injected HibernateTemplate, gets a TODO comment.

io.moderne.java.spring.hibernate.MigrateHibernateTemplateToSession
mod run . --recipe=io.moderne.java.spring.hibernate.MigrateHibernateTemplateToSession

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.