Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chungykang.springdemo.dao;
- import java.util.List;
- import javax.transaction.Transactional;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.query.Query;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Repository;
- import com.chungykang.springdemo.entity.Customer;
- @Repository // Always applied to DAO implementations
- public class CustomerDAOImpl implements CustomerDAO {
- // Need to inject the session factory
- @Autowired
- private SessionFactory sessionFactory;
- @Override
- @Transactional
- public List<Customer> getCustomers() {
- // Get current Hibernate session
- Session currentSession = sessionFactory.getCurrentSession();
- // Create a query
- Query<Customer> theQuery =
- currentSession.createQuery("from Customer", Customer.class);
- // Get list of customers from Query
- List<Customer> customers = theQuery.getResultList();
- // Return the results
- return customers;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement