Created
October 15, 2014 06:15
-
-
Save gabanox/6fad436d25f769c4eb6a to your computer and use it in GitHub Desktop.
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.company.hibernate.dao; | |
import java.util.List; | |
import javax.annotation.Resource; | |
import org.apache.commons.logging.Log; | |
import org.apache.commons.logging.LogFactory; | |
import org.hibernate.SessionFactory; | |
import org.springframework.stereotype.Repository; | |
import org.springframework.transaction.annotation.Transactional; | |
import com.company.hibernate.domain.Contact; | |
@Repository("contactDao") | |
@Transactional | |
public class ContactDaoImpl implements ContactDao { | |
private Log log = LogFactory.getLog(ContactDaoImpl.class); | |
private SessionFactory sessionFactory; | |
//Getters & Setters Omitidos | |
@Transactional(readOnly=true) | |
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