• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

one to many mapping

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your replay.
 
reply
    Bookmark Topic Watch Topic
  • New Topic