I have a Java swing application that uses the MySQL database, in its operation after some time spent in operation I noticed that the application crashed in some moments, it is necessary to restart the computer to be able to perform the process again because even closing the application and again opening the same problem persisted. I was able to identify what the problem caused when recording or updating information. Querying the Workbench I checked the connections and saw that there was a stopped user with the command related to the process.
The state of that connection was like Waiting for table level lock
now I'm not sure that it's causing the problem or something in my application that is not handling 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();
}
}
}