In my Java application Hibernate for bank interaction I use a controller class created even by NetBeans, but the problem I have is the following when doing an edit in some field and only pass this value in the method that I'm going to call and merge all the others that I did not pass are set to null by feeding only the field I passed information.
Below is the method of the controller class that performs the data update.
ProductoDAO.java
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();
}
}
}