1
Guys tried to mount a crud for study and I came across the following situation.
I’m using JPA and hibernate.
When trying to delete a record that has reference in another table is launched an Exception saying that you can not delete pq has reference, until ai ok.
After this Exception appears if I try to add another item appears the same exception that showed when I tried to delete and just below 'Transaction is not active' what may be happening?
DAO
public T inserir(T entity) throws Exception {
try {
manager.getTransaction().begin();
manager.persist(entity);
manager.getTransaction().commit();
} catch (Exception e) {
manager.getTransaction().rollback();
}
return entity;
}`
public void excluir(T entity) {
try {
manager.getTransaction().begin();
manager.remove(entity);
manager.getTransaction().commit();
} catch (Exception e) {
manager.getTransaction().rollback();
}
}
RN
public Item inserir(Item item){
try {
return geralDAO.inserir(item);
} catch (Exception e) {
System.err.println(e.getMessage());
return null;
}
}
public void excluir(Item item){
try {
geralDAO.excluir(item);
} catch (Exception e) {
System.err.println("Erro ao deletar", e.getMessage());
}
}
Present the implementation, it’s easier to guess.
– Matheus
the way I’m using now put in the question above @Matheus
– samuel silva