I tried insert entities to DB. And I have BaseJpaDao class:
@Transactional(Transactional.TxType.REQUIRED)
public abstract class BaseJpaDao<E> implements BaseDao<E> {
protected Class<?> entityClass;
private EntityManager em;
public BaseJpaDao(Class<?> entityClass) {
this.entityClass = entityClass;
em = Persistence.createEntityManagerFactory("COLIBRI").createEntityManager();
}
@Override
public E persist(E e) {
em.persist(e);
return e;
}
...
@Override
public void flush() {
em.flush();
}
And I have child class extends BaseJpaDao
public class CallJpaDao extends BaseJpaDao<Calls> implements CallDao {
and method
@Override
public void insertCalls(List<Calls> callsList) {
for (Calls call : callsList) {
try {
persist(call);
flush();
} catch (Exception e) {
logger.log(Level.FINEST, "Exception in task time={0}. Exception message = {1}.", new Object[]{call.getDate(), e.getMessage()});
}
}
}
I tried persist and flush entity but I have an error:
javax.persistence.TransactionRequiredException: no transaction is in progress
EDIT
I change dependency to
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
</dependency>
It not helped.
And I add @Transactional
annotation to child class - not helped