Hibernate applications may use either container-managed or application-managed connections behind the scenes. We can use IoC in a Hibernate application and configure a data source as a bean. IoC lets us manage the data source transparently and declaratively. Therefore, we can look up the container to obtain the
SessionFactory object initialized with a configured data-source object.
We can assume that
SessionFactory is a singleton bean in the Spring IoC container. However, configuring a
SessionFactory as a bean is not effortless as it has many properties and a complex structure. For this and similar cases, Spring provides a specific type of bean called a factory bean.
A factory bean is a bean inside the IoC container ...