Hi,
I am working on hibernate with the declarative transactions. I am updating the updating the associated child tables and saving the parent table and immediately i am calling session.flush() after updating the child table.
The problem is child tables are not getting updated after calling flush instead these tables are updating after the control comes out of the transaction.
Here is the small scenario for an idea
Code:
// parent class
public class Parent{
......
private Set<Child> childs = new HashSet<Child>(0);
private Set<Friend> friends = new HashSet<Friend>(0);
public Set<Child> getChilds() {
return this.childs;
}
public void setChilds(Set<Child> childs) {
this.childs = childs;
}
public Set<Friend> getFriends() {
return this.friends;
}
public void setFriends(Set<Friend> friends) {
this.friends = friends;
}
}
// child class
Code:
public class Child{
....
private Parent parent;
private Set<Friend> friends = new HashSet<Friend>(0);
public Parent getParent(){
return this.parent ;
}
public void setParent(Parent parent){
this.parent = parent;
}
public Set<Friend> getFriends() {
return this.friends;
}
public void setFriends(Set<Friend> friends) {
this.friends = friends;
}
}
// friend class
Code:
public class Friend{
......
private Parent parent;
private Child child;
public Parent getParent(){
return this.parent ;
}
public void setParent(Parent parent){
this.parent = parent;
}
public Parent getChild(){
return this.child ;
}
public void setChild(Child child){
this.child = child;
}
Quote:
and here is the way throuh which i am updating Child object
Code:
Parent parent = session.get(Parent.class, parentId);
Child child = session.get(Child.class, childId);
Friend friend = new Friend();
//setting the child object into the Friend
friend.setChild(child);
child.getFriends.add(friend);
// now the child object is updated with the new friend record in which i am saving the parent record.
session.saveOrUpdate(parent);
session.flush();
but what the problem is the friend record data is not getting updated immediately after calling session.flush(). The new
Friend record is only update after the control comes out of the Transaction.
Can any one plz help me out why the data is not updating immediately after flush
Thanks
Shiva