Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0
Mapping documents:
in Child mapping file:
<many-to-one name="parent" column="parent_id" not-null="true"/>
in Parent mapping file
<set name="children" inverse="true">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
I have above standard one-to-many association, in the Parent POJO, I also have a standard setter for the children set, like:
public class Parent implements serializable{
Set childrenSet = new HashSet();
...
public void setChildren(Set childrenSet){
this.children = childrenSet;
}
...
}
everything worked fine when I go like:
Parent p = new Parent();
p.setId(1);
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
session.save(p);
But, when I change the setter to following code:
public void setChildren(Set childrenSet){
this.children = new HashSet(childrenSet);
}
I got a problem, hibernate inserted parent and child first, but after that , it did an extra update on parent.
Is there any way to get rid of this extra update?
(The reason of doing this is that we want to pass a standard Set back to the RMI client instead of a Hibernate's Set as we don't want to have client end include hibernate3.jar in the classpath)
Thanks