Java Reference
In-Depth Information
In Spring, @Repository is a stereotype annotation. By annotating it, a component class can be auto-
detected through component scanning. You can assign a component name in this annotation and have
the session factory auto-wired by the Spring IoC container with @Autowired .
package com.apress.springenterpriserecipes.course.hibernate;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
public class HibernateCourseDao implements CourseDao {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
Then you can simply enable the <context:component-scan> element and delete the original
HibernateCourseDao bean declaration.
<beans xmlns=""
base-package="com.apress.springenterpriserecipes.course.hibernate" />
3-11. Persisting Objects with JPA's Context Injection
In a Java EE environment, a Java EE container can manage entity managers for you and inject them
into your EJB components directly. An EJB component can simply perform persistence operations on
an injected entity manager without caring much about the entity manager creation and transaction
Search WWH ::

Custom Search