Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.chortitzer.industria.web.dao.lab; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContextType; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Repository; @Repository @Scope("session") public class DaoImpl_lab implements Dao_lab { //@PersistenceContext(type = PersistenceContextType.EXTENDED) @PersistenceContext(unitName = "PU_lab", type = PersistenceContextType.EXTENDED) private EntityManager em; public EntityManager getEm() { return em; } public void setEm(EntityManager em) { this.em = em; } @SuppressWarnings("unchecked") @Override public <T> List<T> getAll(Class<T> klass) { return em.createQuery("Select t from " + klass.getSimpleName() + " t").getResultList(); } @Override public <T> T save(T t) { T newRecord = null; newRecord = em.merge(t); return newRecord; } @Override public <T> void delete(T t) { em.remove(em.merge(t)); em.flush(); } }