-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Data not updating immediately after flush in transaction
PostPosted: Wed Oct 20, 2010 5:27 am 
Newbie

Joined: Fri May 28, 2010 7:35 am
Posts: 3
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


Top
 Profile  
 
 Post subject: Re: Data not updating immediately after flush in transaction
PostPosted: Wed Oct 20, 2010 5:30 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
That is the point of transactions. To not update anything until "commit" is called. The program is doing exactly what you have written.


Top
 Profile  
 
 Post subject: Re: Data not updating immediately after flush in transaction
PostPosted: Wed Oct 20, 2010 7:26 am 
Newbie

Joined: Fri May 28, 2010 7:35 am
Posts: 3
hi R,

Thanks for the reply. What you posted was absolutely true but if I do the same with saving directly parent table the Friend record table is getting updated before the control comes out of the transaction

Code:
Parent parent = session.get(Parent.class, parentId);

Friend friend  = new Friend();
//setting the parent object into the Friend
friend.setParent(parent);
parent.getFriends.add(friend);

session.saveOrUpdate(parent);
session.flush();


In the above scenario the new friend record is saved before the completion of the transaction.
Please share me if you have any idea about this..

Thanks,
Shiva


Top
 Profile  
 
 Post subject: Re: Data not updating immediately after flush in transaction
PostPosted: Wed Oct 20, 2010 7:38 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Probably I am misunderstanding you, but I do not believe that data could have been updated this way. Would you provide the hibernate log here and indicate what operations you expect there?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.