Hi everone,
I have a samll query. I have a prent and a child class the mapping of which is mentioned below. I add a child to a parent in the following manner by using addChild function in the Parent class
Code:
public void addChild(Child child) {
this.getChildren().add(child);
}
I need to ask that if a parent class has 10,000 children then in order to add 10001 child will hibernate load all the 10,000 children first. If yes is there any other way of preventing this overhead?
Also does using set/list make any difference to the overhead or performance.
Hibernate version:3.0
[b]Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.parentChild">
<class name="Parent">
<id name="id" column="PARENT_ID">
<generator class="increment"/>
</id>
<version name="version" type="long" />
<property name="type"/>
<set name="children" lazy="true" cascade="all" >
<key column="parent_id" not-null="true"/>
<one-to-many class="Child"/>
</set>
</class>
<class name="Child">
<id name="id" column="CHILD_ID">
<generator class="increment"/>
</id>
<many-to-one name="user" column="USER_ID" class="Usr" cascade="all" />
</class>
<class name="Usr" table="USR">
<id name="id" column="USER_ID">
<generator class="increment"/>
</id>
<property name="firstName" type="string" column="firstName" not-null="true"/>
<property name="lastName" type="string" column="lastName" not-null="false"/>
</class>
</hibernate-mapping>
Thanks