summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pom.xml8
-rw-r--r--src/main/java/nu/xss/jpa/dao/AbstractJpaDao.java2
-rw-r--r--src/main/java/nu/xss/jpa/dao/Dao.java4
-rw-r--r--src/main/java/nu/xss/jpa/dao/GenericJpaDao.java13
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 @@
<modelVersion>4.0.0</modelVersion>
<groupId>nu.xss</groupId>
<artifactId>xss-jpa</artifactId>
- <version>0.0.1-SNAPSHOT</version>
+ <version>0.0.2-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate.version>4.1.4.Final</hibernate.version>
+ <slf4j.version>1.6.1</slf4j.version>
</properties>
<dependencies>
@@ -21,6 +22,11 @@
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
</dependencies>
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<E, K> implements Dao<E, K>, Serializable {
private static final long serialVersionUID = 4998055731089977476L;
- @PersistenceContext(unitName="mainPU")
+ @PersistenceContext
protected EntityManager entityManager;
protected Class<E> 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<E, K> {
- void persist(E entity);
- void remove(E entity);
+ void save(E entity);
+ void delete(E entity);
E findById(K id);
List<E> 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<E,K> implements Dao<E,K>, 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<E,K> implements Dao<E,K>, Serializable {
@SuppressWarnings("unchecked")
public GenericJpaDao() {
ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
- this.entity = (Class<E>) genericSuperclass.getActualTypeArguments()[1];
+ this.entity = (Class<E>) 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);
}