1
Using the @Version Annotation, shows this error when trying to update.
18:25:16.650 [http-nio-8080-exec-84] ERROR br.com.netsoft.controller.todos.Updatemanetariaitemcontroller - Row was updated or Deleted by Another transaction (or Unsaved-value Mapping was incorrect) : [br.com.netsoft.model.todos.Updatemanetariaitementity#8]
When you insert is working.
Is mapped like this
@Version
@Column(name = "NR_VERSAO", nullable = false)
public int getNrVersao() {
return nrVersao;
}
Method of altering
@Transactional
@Repository
public class BaseRepositorio<T> {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@PersistenceContext
protected EntityManager entityManager;
public EntityManager getEntityManager() {
return entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public T inserir(T objeto) throws Exception {
this.entityManager.persist(objeto);
return objeto;
}
public T alterar(T objeto) throws Exception {
return merge(objeto);
}
private T merge(T objeto) {
this.entityManager.detach(objeto);
this.entityManager.merge(objeto);
return objeto;
}
}
The problem seems to be before this. Who calls this merge method? but if it were you I would use the original behavior of
merge
(unuseddetach
).– Dherik