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.AutomationMonetariaItemController - Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [br.netsoft.model.all.additional.content] # 8]
When inserting is working.
It is mapped so
@Version
@Column(name = "NR_VERSAO", nullable = false)
public int getNrVersao() {
return nrVersao;
}
Change method
@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;
}
}