In my stream it looks like this:
- I already have an object stored in the database.
- When loading my page, these objects are fetched in the database, treated to be displayed.
- Objects arrive in a List (
List
), that is iterated byfor
to receive the appropriate treatments. - While an object is handled, I make a query of
webservice
receiving another object. I make a comparison between objects and if there is a difference, the object that came from the database needs to be updated.
Basically this is, the problem occurs is that I update my object and have it updated in the database but does not update. Can someone give me a help?
The method you are looking for in the database:
public void pesquisar() {
List<Objeto> objetos = new ArrayList<>();
objetos = service.findAll();
this.encomendas = new ArrayList<>();
if (CollectionUtils.isNotEmpty(objetos)) {
try {
for (Objeto objeto : objetos) {
houveAlteracao(objeto);
ajustarInformacoes(objeto);
}
ordenarLista();
horaAtualizacao = new Date();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Now the houveAlteracao()
method:
private void houveAlteracao(Objeto objeto) {
try {
final Objeto obj = popularObjeto(objeto.getCodigo());
if (obj.getEventos().size() > objeto.getEventos().size()) {
objeto.setEventos(obj.getEventos());
service.update(objeto);
} else {
}
} catch (Exception e) {
e.printStackTrace();
}
}
In this method if getEventos.size()
that belongs to the searched object in webservice
is higher, the database object must receive these values and then updated, the problem is that the command is applied but does not update. And finally the update command:
public void update(Objeto objeto) {
this.em.merge(objeto);
}
Does anyone help please?