3
In my flow it’s like this:
- I already have an object stored in the database.
- When loading my page, these objects are searched in the database, treated to be displayed.
- Objects arrive in a List (
List
), of this is iterated by afor
to receive the appropriate treatments. - While an object is treated, I make a query of
webservice
receiving another object. I make a comparison between the objects and if there is a difference, the object that came from the database needs to be updated.
Basically that’s it, the problem occurs is that I update my object and have it updated in the database but not updated. Can someone give me a help ?
The method you search in the bank:
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 method houveAlteracao()
:
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()
which belongs to the object searched in webservice
is larger, the database object must receive these values and then updated, the problem is that the command is applied but not updated. And finally the update command:
public void update(Objeto objeto) {
this.em.merge(objeto);
}
Somebody please help me ?
You can add fields to some table if necessary?
– Victor Stafusa
If your object is managed by Hibernate you should use the method
update()
instead ofmerge()
. If it is not managed by Hibernate you should use themerge()
and then call the methodpersist()
. I think this. Always confusing me with these methods hehe– igventurelli
@Victorstafusa did not understand your question.
– Roknauta
The problem is actually another. I’m going to create a new question.
– Roknauta