createAll
This commit is contained in:
snoop 2017-06-07 20:14:55 +09:00
parent ab7e579b52
commit 809f91c195
2 changed files with 18 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import java.lang.reflect.ParameterizedType;
import java.util.List;
/**
* Created by insanity on 17. 5. 25.
@ -41,6 +42,22 @@ public class JPABaseDAO<T> implements BaseDAO<T> {
return entity;
}
public int createAll(List<T> entityList) {
EntityTransaction tx = this.entityManager.getTransaction();
if (!tx.isActive()) tx.begin();
try {
for(T ent : entityList) {
this.entityManager.persist(ent);
}
tx.commit();
}catch(Exception e) {
tx.rollback();
return 0;
}
return entityList.size();
}
public T update(T entity) {
EntityTransaction tx = this.entityManager.getTransaction();
if (!tx.isActive()) tx.begin();

View File

@ -9,6 +9,6 @@ import org.junit.Test;
public class AppTest {
@Test
public void testSum() {
fail("Not yet implemented");
// fail("Not yet implemented");
}
}