Thursday, June 20, 2013

Spring Hibernate: bookstore.dao.BaseDaoImpl.java


package bookstore.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository ( value = "baseDao")
@Transactional
public class BaseDaoImpl implements BaseDao {

@PersistenceContext
private EntityManager em;

@Override
public void persist(Object obj) {
em.persist(obj);

}

@Override
public <T> List<T> getAll(Class<T> clazz) {
       TypedQuery<T> query = em.createQuery(" from " + clazz.getName(), clazz);
  return query.getResultList();
}

}

No comments:

Post a Comment