Skip to content

Instantly share code, notes, and snippets.

@mak9456
Last active September 25, 2018 07:06
Show Gist options
  • Save mak9456/effb5b23bcd7f22c196dde189ef9c6c8 to your computer and use it in GitHub Desktop.
Save mak9456/effb5b23bcd7f22c196dde189ef9c6c8 to your computer and use it in GitHub Desktop.
CustomerDao implementation
@Repository
public class CustomerDaoimpl implements CustomerDao{
@Autowired
public SessionFactory sessionfactory;
@Override
public List<Customer> getCustomer() {
Session currentsession=sessionfactory.getCurrentSession();
List<Customer> customers=currentsession.createQuery("from Customer",Customer.class).getResultList();
return customers;
}
@Override
public Boolean addCustomer(Customer customer) {
try {
Session currentsession=sessionfactory.getCurrentSession();
currentsession.save(customer);
} catch (Exception e) {
// TODO: handle exception
return false;
}
return true;
}
@Override
public Customer getSingleCustomer(int theId) {
Session currentsession=sessionfactory.getCurrentSession();
return currentsession.get(Customer.class,theId);
}
@Override
public void deleteCustomer(int theId) {
Session currentsession=sessionfactory.getCurrentSession();
currentsession.delete(getSingleCustomer(theId));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment