I'm working JPA, I run the following update:
public int EditarUsuario(UserSys us) {
EntityManager em = getEntityManager();
em.getTransaction().begin();
try {
Query q = em.createNativeQuery("UPDATE 'user_sys' "
+ "SET "
+ "'USER_NOM' = ?, "
+ "'USER_ESTADO' = ?, "
+ "'USER_ROL' = ? "
+ "WHERE 'USER_ID' = ?; ");
q.setParameter(1, us.getUserNom());
q.setParameter(2, us.getUserEstado());
q.setParameter(3, us.getUserRol());
q.setParameter(4, us.getUserId());
int v = q.executeUpdate();
em.getTransaction().commit();
return v;
} catch (javax.persistence.NoResultException ex) {
return 0;
} finally {
em.close();
}
}
It works perfectly, since when I run the query on mysql I see the update directly, however when I do the select * from
of that table I do not see the changes in jpa:
public List<UserSys> Buscartodos() {
EntityManager em = getEntityManager();
em.clear();
try {
Query q = em.createNativeQuery("SELECT * FROM user_sys ;", UserSys.class);
List<UserSys> lista=q.getResultList();
return lista;
} catch (javax.persistence.NoResultException ex) {
return null;
} finally {
em.close();
}
}
I have done inserts and they work and update the data, in this case that may be happening?