Created
January 15, 2018 15:50
-
-
Save darbyluv2code/dec1893c321dd138ab70d5507439767e to your computer and use it in GitHub Desktop.
CustomerDAOImpl.java (check that you have the same imports)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.luv2code.springdemo.dao; | |
| import java.util.List; | |
| 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 org.springframework.transaction.annotation.Transactional; | |
| import com.luv2code.springdemo.entity.Customer; | |
| @Repository | |
| public class CustomerDAOImpl implements CustomerDAO { | |
| // need to inject the session factory | |
| @Autowired | |
| private SessionFactory sessionFactory; | |
| @Override | |
| @Transactional | |
| public List<Customer> getCustomers() { | |
| // get the current hibernate session | |
| Session currentSession = sessionFactory.getCurrentSession(); | |
| // create a query | |
| Query<Customer> theQuery = | |
| currentSession.createQuery("from Customer", Customer.class); | |
| // execute query and get result list | |
| List<Customer> customers = theQuery.getResultList(); | |
| // return the results | |
| return customers; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment