Is it possible to define default object inside a SET element in HBM?
lets say I have mapping of a set within Parent hbm file:
<set cascade="all" inverse="true" lazy="false" name="chil开发者_运维问答dren">
<key column="parentChildId" foreign-key="fk_fk" not-null="true" on-
delete="cascade"/>
<one-to-many class="Child" not-found="ignore"/>
</set>
Is it anyhow possible to define in Parent hbm a default child, that when ever parent is created, one child is added inside of this set????
I know it sounds weird, but because of some performance issue i must try to create as least calls to server (here one was saving parent and other call was saving default child).
I appreciate all the help.
Thank you
What do you mean by "server"? Do you mean the database server? If so, then there's no way to create a parent and a child in one SQL statement. But Hibernate uses batch updates, so it should be very efficient.
If you mean the "application server", then it sounds like a functional problem, not a technical one. Change your parent creation method to make it create a child at the same time. You could even do that using a factory method in the Parent class :
public class Parent {
public static Parent createParentWithDefaultChild() {
Parent p = new Parent();
p.addChild(new Child());
return p;
}
// ...
}
精彩评论