Java.lang.IllegalStateException: Transaction not active

Meu problema:

 nota = daoNota.save(nota);
                for (int i = 0;
                        i < notasMaterias.size();
                        i++) {
                    notaMaterial = notasMaterias.get(i);
                    notaMaterial.setNotaFiscal(nota);
                    empenhoMateriall.setQuantEntregue((empenhoMateriall.getQuantidade() - (notaMaterial.getQuantidade())));
                    dao.save(notaMaterial);
                    empenhoMateriall = notaMaterial.getEmpenhoMaterial();
                    daoEmpenhoMaterial.update(empenhoMateriall);
                }
                init();
                msg = "Nota Fiscal cadastrada com sucesso!!";
                return "/pages/notaFiscal/pesquisarNotaFiscal.jsf?faces-redirect=true";

o erro acontece nesta linha

daoEmpenhoMaterial.update(empenhoMateriall);

Provável que você não renove a transação após esta linha

dao.save(notaMaterial);

Como faço para renovar!
Obrigado!!

Depende de como implementou o método.
Se está usando Session, provável que em algum lugar tenha chamado o commit.
Vai precisar reabrir a transaction, invocando o método beginTransaction novamente.
Fica algo como abaixo

[code]
Session s = null;
Transaction t = null;

try {
s = HibernateSession.instance().getSessionFactory().openSession();
t = s.beginTransaction();//Aqui você renova a transaction

 ...
 ...

} finally {
t.commit();
s.close();
}[/code]
Só não estou levando em consideração boas práticas.

Olha o meu metodo de upgrade

public T update(T entity) {
try {
getEntityManager().getTransaction().begin();
getEntityManager().merge(entity);
getEntityManager().getTransaction().commit();
getEntityManager().close();
} catch (Exception e) {
getEntityManager().getTransaction().rollback();
}
return entity;
}

Está usando JPA.
Precisa ver como está no método save…

Sim uso JPA e uma classe com todos os metos (save, upgrade, dele)


private EntityManager entityManager;
    private final Class<T> persistentClass;
    private Session session;

    public GenericDAOImp(Class<T> classe) {
        this.persistentClass = classe;
        this.entityManager = new JPAMF().getEntityManager();
    }

    public Class<T> getPersintentClass() {
        return this.persistentClass;
    }

    public void setEntityManager(EntityManager em) {
        this.entityManager = em;
    }

    protected EntityManager getEntityManager() {
        if (this.entityManager == null) {
            throw new IllegalStateException("Erro:");
        }
        return entityManager;
    }

    public T save(T entity) {
        getEntityManager().clear();
        getEntityManager().getTransaction().begin();
        getEntityManager().persist(entity);
        getEntityManager().getTransaction().commit();
        return entity;
    }


    public T update(T entity) {
        try {
            getEntityManager().getTransaction().begin();
            getEntityManager().merge(entity);
            getEntityManager().getTransaction().commit(); 
            getEntityManager().close();
            getEntityManager().getTransaction().begin();
        } catch (Exception e) {
            getEntityManager().getTransaction().rollback();
        }
        return entity;
    }

    public void delete(T entity) {
        getEntityManager().getTransaction().begin();
        entity = getEntityManager().merge(entity);
        getEntityManager().remove(entity);
        getEntityManager().getTransaction().commit();
    }