This commit is contained in:
tuanvu
2025-09-17 15:32:50 +02:00
parent 90d30634d7
commit d47024314a
9 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package DAO;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.PersistenceException;
import jpa.EntityManagerHelper;
import java.io.Serializable;
public abstract class TousDAOImpl<T, Id extends Serializable> implements Tous<T, Id> {
protected EntityManager em;
private Class<T> entityClass;
public TousDAOImpl() {
this.em = EntityManagerHelper.getEntityManager();
}
@Override
public T save(T t) {
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
em.persist(t);
tx.commit();
return t;
} catch (PersistenceException e) {
throw new PersistenceException(e.getMessage());
}
}
}