Skip to content

Instantly share code, notes, and snippets.

@gabanox
Created October 14, 2014 04:38
Show Gist options
  • Save gabanox/f3e1917922b0a9aa113d to your computer and use it in GitHub Desktop.
Save gabanox/f3e1917922b0a9aa113d to your computer and use it in GitHub Desktop.
public List<Contact> findAll() {
return sessionFactory.getCurrentSession().createQuery("from Contact c").list();
}
public List<Contact> findAllWithDetail() {
return sessionFactory.getCurrentSession().getNamedQuery("Contact.findAllWithDetail").list();
}
public Contact findById(Long id) {
return (Contact) sessionFactory.getCurrentSession().
getNamedQuery("Contact.findById").setParameter("id", id).uniqueResult();
}
public Contact save(Contact contact) {
sessionFactory.getCurrentSession().saveOrUpdate(contact);
log.info("Contact saved with id: " + contact.getId());
return contact;
}
public void delete(Contact contact) {
sessionFactory.getCurrentSession().delete(contact);
log.info("Contact deleted with id: " + contact.getId());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment