I have an object Sample that contains a Collection of Foo objects.
public class Sample {
private String name;
private List<Foo> fooList;
public String getName() {
return name;
}
public void setName(String n) {
name = n;
}
public List<Foo> getFooList() {
return fooList;
}
public void setFooList(List<Foo> list) {
fooList = list;
}
}
The objects Sample and Foo are correctly mapped in Hibernate.
I open ah Hibernate transaction and I have in a cache an instance of Sample with "name" = "tommaso". Someone modifiy in the DB that row and change name in "massimo". If I want to refresh the instance in cache, I write
Sample sample = ...;
session.refresh(sample);
Hibernate refresh the instance of Sample object and the attribute name became "massimo". It works!
If someone edit the collection of this instance, and delete one Foo in the fooList, when I do refresh of that instance Sample, Hibernate throws no row with the given identifier exists.
How can I refresh the session cache with real situation in the db?