I have a web application that has to add data to a database and I have to do this for 1000 entities. Everything goes well until the 10th iteration and then when entering the method that does the persist I get cannot acquire JDBC connection at the line which opens the transaction. I will add the method below. Does anyone know what I should do?
@PersistenceUnit(unitName = "current_project")
private EntityManagerFactory entityManagerFactory;
public long persistAccountObject(AccountObject accountObject) {
    long pdAccmAccountManagerId = 0;
    try {
        logger.debug("Start Persisting...");
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();
        entityManager.persist(accountObject);
        entityManager.getTransaction().commit();
        // unique ID
        accountId= accountObject.getId();
        logger.debug("Persisting OK...");
    }
    catch (PersistenceException persistenceException) {
        logger.error("PersistenceException occur", persistenceException);
    }
    catch (Exception e) {
        logger.error("Exception occurs", e);
    }
    return accountId;
}
The exception occurs at the line with entityManager.getTransaction().begin() at the 10th iteration every time. Until then, I get the objects persisted in the database.
I tried to add the hibernate-c3p0 dependency in the pom and set some properties for it in the persistence.xml, but if I do that, my program gets blocked and does not even start running.
What should I do?
 
    