-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: mapping with 3 tables
PostPosted: Wed Feb 07, 2007 12:41 pm 
Newbie

Joined: Wed Feb 07, 2007 12:21 pm
Posts: 2
Hi All,
I am new to hibernate
I am working for a security project which is being developed in Spring and Hibernate. In this project a new request will be created when a new employ joins the organization. This request will contain information to different office sites and floor areas within the sites. I need to store this information in the table. I have created three tables. Request, Site and floors. Now I need to map these three tables. Each request will consist of n number of sites and with these site I need to store n number of floors. Can you help me out ?

Thanx & Rgds
Nicky


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 8:10 pm 
Newbie

Joined: Wed Feb 07, 2007 6:05 pm
Posts: 10
It sounds like you have this relationship


Request --> Sites is one-to-many
Sites --> Floors is one-to-many

Floors -->Site is many-to-one
Sites --> Requets is many-to-one


Create a set in the Request mapping
<set name="sites" inverse="true" cascade="all">
<key column="REQUEST_ID"/>
<one-to-many class="SiteClass"/>
</set>

Create a set and a many-to-one in the Site mapping
<set name="floors" inverse="true" cascade="all">
<key column="SITE_ID"/>
<one-to-many class="FloorClass"/>
</set>
<many-to-one name="request" class="RequestClass" column="REQUEST_ID"/>

and finally create a many-to-one in the Floor mapping
<many-to-one name="site" class="SiteClass" column="SITE_ID"/>

Your RequestClass needs to have a Set containing the SiteClass and your SiteClass will need a Set containing the FloorClass


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 5:39 am 
Newbie

Joined: Wed Feb 07, 2007 12:21 pm
Posts: 2
kshenes thank you for your help.

But the real problem is on storing the request information.

For example I have two sites say Site1 and Site2 in Site table
Site1 has three floors (Site1_Floor1, Site1_Floor2, Site1_Floor3)
Site2 has two floors (Site2_Floor1, Sit2_Floor2).

A request will have any combination of access to the Site floors
For example
Request1 may contain request to access Site1_Floor1, Site1_Floor3, Site2_Floor1
Request2 may contain request to access Site1_Floor2, Site2_Floor2

I need to store this information in the database using Many-to-Many relationships with intermediate tables

Can you help me out!

Thanks
Nicky


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.