Back Forum Reply New

Adding a component (vs. entity) child

In a parent-children relationship, those children are components, but not entities. When I want to add a new child to its parent, I do the followings:

Code:
Class Parent{    //...    Setlt;Childgt; children = new HashSetlt;Childgt;;
   // ...   public void addChild(Child c){        c.setParent(this);        children.add(c);    lt;---- this line causes the lazy initialization error exception   }
  // ...
}
And in my Spring business layer, I have

Code:
parent.addChild(child);
this.parentDao.makePersistent(parent);
The above leads to a lazy initialization exception. So, how to add a component to its parent?

The above is in the Hibernate content.

Hello
In a parent-children relationship, those children are components, but not entities.

i dont understand, what are you trying to say with components instead of entities?

this example appear in hibernate documentation, something like the cat and kitties case

your code looks fine, each element that you add in your object should be a object too

i dont see hbm code file

regards


Originally Posted by dr_pompeiiHello

i dont understand, what are you trying to say with components instead of entities?

this example appear in hibernate documentation, something like the cat and kitties case

your code looks fine, each element that you add in your object should be a object too

i dont see hbm code file

regards

That is one approach. In this approach, the DB table is a cross reference one with some extra columns. Of course, I can use other approaches including having the child as an entity.

Anyway, here is the mapping file (only related sections)

Code:
lt;class name=quotarentquot; table=quot;parentquot;gt;
...   lt;set name=quot;childrenquot; table=quot;childquot; cascade=quot;save-update, merge,delete-orphanquot;gt;       lt;key column=quotARENT_IDquot; foreign-key=quot;ID_FKEYquot;/gt;       lt;composite-element class=quot;Childquot;gt;lt;parent name=quot;parentquot;/gt;
         ...
       lt;/composite-elementgt;    lt;/setgt;  ...
lt;/hibernate-mappinggt;long time ago that i dont use this way

like i said check the hibernate example,
free code for Java and hbm xml code appear

thats must be enough


Originally Posted by dr_pompeiilong time ago that i dont use this way

like i said check the hibernate example,
free code for Java and hbm xml code appear

thats must be enough

In fact, I already dipped in Hibernate reference document and samples before I posted my this question.
¥
Back Forum Reply New