I need to check if my actual entity is different from the old one.
I use reflection because my method must be standardized.
For each column, I update the value if and only if it's not null (because i read it from a CSV and a column may be not specified).
for(Field column : fields){
column.setAccessible(true);
Object newValue = column.get(myObject);
if( newValue != null && !newValue.equals(column.get(oldObject))){
column.set(oldObject, newValue);
}
}
this.entitymanager.merge(oldObject)
If I do the changes like that, no UPDATE query is done.
If I change the value in the normal way oldobject.setValue(newValue)
the query is done and the record is updated.
Why no UPDATE query is done by the entity manager if I change value via reflection?