Originally posted by ramesh kancherla:
HI
why we need to define hashset and
if I saved parent bean it contains hashset then its childeren beans will save or not
can any one please tell me
Thanks & Regards
Ramesh K
I have an Employee Class,this will have empId,empName and empAddress. In my scenario one employee may have more than one address.
Address can have more attributes say like Street/Block/Boulevard pincode etc..
I have 2 classes here, one for Employee and ADDRESS ...
Here is my code below
public class Employee implements Serializable //better to serialize your POJO's {
private
String id;// will be generated by hibernate
private String empName;
private Set<ADDRESS> address;
//setter and getter.
}
public class Address implements Serializable {
//Address specific attributes
}
hbm entries
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hibernate.Employee" table="EMPLOYER">
<id column="EMP_ID" name="id" type="java.lang.Long">
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">idgen</param>
<param name="column">NEXT</param>
</generator>
</id>
<property column="EMP_NAME" name="empName" type="java.lang.String"/>
<set name="address" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="EMP_ID" />
<one-to-many class="com.hibernate.address" />
</set>
The above hbm entry depicts that your EMP table EMP_Id has reference to your ADDRESS Table.
Coming to your point..
if I saved parent bean it contains hashset then its childeren beans will save or not Before saving your Parent object you need to populate the child objects such way that you are in need of HashSet to be defined for your hbm and POJO's.
Hope this clarifies..
Correct me If I am wrong.