0
I use Hibernate in my Java application for database interaction using a controller class created even by Netbeans, but the problem I have is this: when making an edit in some field and only pass this value in the method I will call and merge all the others that I did not pass are set as null feeding only the field I passed information.
Below is the method of the controller class that updates data.
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();
}
}
}
Clayton, to better help you, it would be necessary that the Product class and the update of the same be in the body of the question, if not solved, adds there that we will be happy to help you.
– Elyel Rubens da Rosa