-->
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.  [ 1 post ] 
Author Message
 Post subject: Automatic bidirectional class members synchronization
PostPosted: Wed Jun 30, 2010 3:34 pm 
Newbie

Joined: Wed Jun 30, 2010 2:59 pm
Posts: 1
Hi,

sorry if this is a recurrent subject, but reading the Hibernate Docs and searching in the forum I didn't found an answer, or I'm not knowing how to search!

Is there a way to let Hibernate automatically deals with the synchronization between class members of ManyToOne and OneToMany?

For example:

Code:
@Entity
class Parent
{
    ...
   @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
    private List<Child> childList;   
   ...
}

@Entity
class Child
{
   ...
   @ManyToOne
   private Parent parent;
   ...
}


When I do:

Code:
Parent parent = new Parent();
Child child = new Child();
child.setParent(parent);


What I want is the childList of the parent to be automatically synchronized, so if I do:

parent.getChildList() the previously child will be in the list.

Is this possible? Or I need to manually deal with this, removing and adding the child from the parent List each time the child's parent changes?

Note: I know that if I load the parent object in another hibernate session, the collection will be proper loaded, but what I need is this synchronization happening inside the same session and without calling flush() refresh(). What I need is my business logic working the same way, independently if I call it in different sessions or in the same session.

Thanks,
Rafael Ceravolo


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

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.