aspose file tools*
The moose likes Object Relational Mapping and the fly likes one to many mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "one to many mapping" Watch "one to many mapping" New topic
Author

one to many mapping

ramesh kancherla
Ranch Hand

Joined: May 01, 2008
Posts: 124
Hi,
This is Ramesh. I am not understanding why we need to define hashset in
one to many mapping.



can any one please tell me what is actual purpose of Hashset in one to many
mapping.

Thanks & Regards
Ramesh K
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

there is nothing hard and fast that hash sets should be used. you could even use arraylists for the same, but if you have mapped your many in your ORM using list tags.
Again, Iam assuming that you are using hibernate here. We would be happy if could provide more details about the ORM you are using and what made you raise this doubt?


If you are not laughing at yourself, then you just didn't get the joke.
ramesh kancherla
Ranch Hand

Joined: May 01, 2008
Posts: 124
HI

I have seen in hbm file as


and in bean as



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
Ramesh Srinivasan
Ranch Hand

Joined: Aug 17, 2008
Posts: 35
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.


SCJP 5.0 93%<br /> <br />"We are what we repeatedly do , then excellence is not an action it is an Habit" Aristotle
ramesh kancherla
Ranch Hand

Joined: May 01, 2008
Posts: 124
Hi,
Thanks for your replay.
 
wood burning stoves
 
subject: one to many mapping