From 3571512d36c3aec28fdc8aa76c01f520f0c5fdbd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 3 Jun 2012 16:07:07 +0200 Subject: fix gernericdao; add logging --- pom.xml | 8 +++++++- src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java | 2 +- src/main/java/nu/xss/jpa/dao/Dao.java | 4 ++-- src/main/java/nu/xss/jpa/dao/GenericJpaDao.java | 13 ++++++++----- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 2ce7f48..ec596d8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,11 +3,12 @@ 4.0.0 nu.xss xss-jpa - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT UTF-8 4.1.4.Final + 1.6.1 @@ -21,6 +22,11 @@ hibernate-entitymanager ${hibernate.version} + + org.slf4j + slf4j-api + ${slf4j.version} + diff --git a/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java b/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java index aef1aaf..b1638ac 100644 --- a/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java +++ b/src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java @@ -10,7 +10,7 @@ public abstract class AbstractJpaDao implements Dao, Serializable { private static final long serialVersionUID = 4998055731089977476L; - @PersistenceContext(unitName="mainPU") + @PersistenceContext protected EntityManager entityManager; protected Class entity; diff --git a/src/main/java/nu/xss/jpa/dao/Dao.java b/src/main/java/nu/xss/jpa/dao/Dao.java index b91c834..18d886f 100644 --- a/src/main/java/nu/xss/jpa/dao/Dao.java +++ b/src/main/java/nu/xss/jpa/dao/Dao.java @@ -3,8 +3,8 @@ package nu.xss.jpa.dao; import java.util.List; public interface Dao { - void persist(E entity); - void remove(E entity); + void save(E entity); + void delete(E entity); E findById(K id); List findAll(); } diff --git a/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java b/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java index 5acfffc..c5c2d91 100644 --- a/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java +++ b/src/main/java/nu/xss/jpa/dao/GenericJpaDao.java @@ -7,9 +7,13 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public abstract class GenericJpaDao implements Dao, Serializable { private static final long serialVersionUID = 4998055731089977476L; + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @PersistenceContext protected EntityManager entityManager; @@ -19,15 +23,14 @@ public abstract class GenericJpaDao implements Dao, Serializable { @SuppressWarnings("unchecked") public GenericJpaDao() { ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass(); - this.entity = (Class) genericSuperclass.getActualTypeArguments()[1]; + this.entity = (Class) genericSuperclass.getActualTypeArguments()[0]; } - public void persist(E entity) { - entityManager.persist(entity); - + public void save(E entity) { + entityManager.merge(entity); } - public void remove(E entity) { + public void delete(E entity) { entityManager.remove(entity); } -- cgit v1.2.3-55-g7522