I use Spring 3, Hibernate 3.3.1 and MySQL 5.1.x (in red hat 5 they also see the same behavior as in Windows). I notice that the row in the database is being updated, but one of the references to objects in memory is not being updated. I will try to describe the structure of the class in a simplified form.
class A {
@OneToMany(cascade = CascadeType.ALL)
List<Widget> widgets;
@OneToMany(cascade = CascadeType.ALL)
@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
List<B> bObjects;
@Transactional
public void turnOnWidgets() { ... }
}
class B {
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@Cascade(value = { org.hibernate.annotations.CascadeType.LOCK, org.hibernate.annotations.CascadeType.EVICT})
private A aObj;
@Transactional(propagation=Propagation.REQUIRES_NEW)
public void turnOnWidgets() {
for (Widget w : aObj.getWidgets()) {
w.setOn(true);
}
}
}
class Widget {
Boolean on;
}
Here is the sequence of actions. When A.turnOnWidgets is called, it iterates through its "bObjects" collection and calls "turnOnWidgets" for each object B. Object B changes the "on" property for each widget referenced by object A (as shown above in B.turnOnWidgets) .
, , "on" . , , , B A (, A , - Java), A, "turnOnWidgets", .
, , , A, Widgets "on" . , , B.aObj.getWidgets(), "on" true.
Oracle, , MySQL, .
- , - MySQL (, Hibernate / Spring)?
UPDATE
, , "" JPA "B". oracle , MySQL . , .