Listing 9-12 shows that the ContactDaoImpl class contains the samples in this chapter. The
configured Hibernate SessionFactory was injected into the class.
Listing 9-12. Injecting Hibernate SessionFactory
package com.apress.prospring3.ch9.dao.hibernate;
// Import statements omitted
@Repository("contactDao")
@Transactional
public class ContactDaoImpl implements ContactDao {
// Other code omitted
private Log log = LogFactory.getLog(ContactDaoImpl.class);
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
@Resource(name="sessionFactory")
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
As usual, we declare the DAO class as a Spring bean with data access logic using the @Repository
annotation. The @Transactional annotation defines the transaction requirements that we will discuss in
Chapter 13. The sessionFactory attribute was set to be injected by using the @Resource annotation.
Database Operations with Hibernate
In this section, we will discuss how to perform database operations in Hibernate. Listing 9-13 shows the
ContactDao interface, which indicates the contact data access services we are going to provide.
Listing 9-13. The ContactDao Interface
package com.apress.prospring3.ch9.dao;
import java.util.List;
import com.apress.prospring3.ch9.domain.Contact;
public interface ContactDao {
// Find all contacts
public List<Contact> findAll();
// Find all contacts with telephone and hobbies
public List<Contact> findAllWithDetail();
// Find a contact with details by id
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home