Skip to content

Instantly share code, notes, and snippets.

@jeevan-patil
Created May 17, 2013 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeevan-patil/5597355 to your computer and use it in GitHub Desktop.
Save jeevan-patil/5597355 to your computer and use it in GitHub Desktop.
Sample Spring DAO repository class.
package com.transbank.online.dao.impl;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import com.transbank.online.bean.Customer;
import com.transbank.online.dao.iface.CustomerDao;
/**
*
* @author jeevan
* @since Apr 30, 2013
* @purpose
*
*/
@Repository("customerDao")
public class CustomerDaoImpl implements CustomerDao {
private SessionFactory sessionFactory;
@Override
public Customer getCustomerById(String id) throws Exception {
Session session = sessionFactory.openSession();
Customer customer = (Customer) session.get(Customer.class, id);
session.flush();
session.close();
return customer;
}
@Autowired
@Qualifier("sessionFactory")
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment