0
I have a Java swing application that uses the Mysql database, in its operation after spending some time in operation I realized that the application hangs in a few moments, It is necessary to restart the computer to be able to carry out the process again because even closing the application and opening again the same problem persisted. I was able to identify that the problem occurred at the time of recording or updating information. Consulting the Workbench I checked the connections and saw that there was a user stopped with the command related to the process.
The state of that connection was as Waiting for table level lock
now I am not sure that it is she who is causing the problem or something of my application that is not treating correctly.
DAO.java
public int create(Produto produto) {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
em.persist(produto);
em.getTransaction().commit();
} finally {
if (em != null) {
em.close();
}
}
return produto.getCodproduto();
}
public void edit(Produto produto) throws NonexistentEntityException, Exception {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
produto = em.merge(produto);
em.getTransaction().commit();
} catch (Exception ex) {
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
Integer id = produto.getCodproduto();
if (findProduto(id) == null) {
throw new NonexistentEntityException("The produto with id " + id + " no longer exists.");
}
}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
}
You’re committing and closing the transaction correctly?
– adelmo00
I will update the issue by adding the code you requested.
– DevAgil