-->
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.  [ 6 posts ] 
Author Message
 Post subject: Newbie Mapping Question
PostPosted: Fri Nov 17, 2006 1:19 pm 
Newbie

Joined: Fri Nov 17, 2006 1:00 pm
Posts: 6
Hi Guys,

I am VERY new to Hibernate... I've been doing my research though, and finally have gotten to the point where things are becoming a bit clearer -- but I am very confused on how to do this mapping.

I have 3 tables in my database:

Site_Ref, Network_Ref, and Site_Network_Ref.

Site_Ref's primary key is site_id
Network_Ref's primary key is network_id
Site_Network_Ref has 2 foreign keys -- site_id and network_id that reference the above respective tables.

I have a web service where I am given a site id. I then need to look up this site id against the site_network_ref table to retrieve all network id's that belong to that site id. Multiple network id's can correspond to a single site id (but not the other way around). I then need to look in the network_ref table (by each network id that matched the site id), and retrieve information from that table for each row.

So the question is.. how the heck do I map this in hibernate? I'm thinking that I am going to have to incorporate that Set attribute and many to one stuff, but I am still very fuzzy on the actual implementation details. Can anyone give some guidance?

So far what I have done is create a domain object for the network ref table, and a mapping for that, and a domain object for the site_network_ref table, and a mapping for that as well. However, the two don't "see" each other as of yet because I haven't included any reference from one to the other.

Thanks in advance for your help.. it is much appreciated.

- Jessica


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 1:22 pm 
Newbie

Joined: Fri Nov 17, 2006 1:00 pm
Posts: 6
Oh, I forgot to add -- I am mapping with XML files.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 1:37 pm 
Newbie

Joined: Mon Nov 13, 2006 11:49 am
Posts: 6
Look at using Middlegen. You pass Middlegen a couple of parameters for connecting to your DB and its GUI will show you, your ERD which will allow you edit any properties you might want to edit. Then click the Generate button. It will generate accurate and complete HBM's.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 1:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...or use hibernate tools ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 2:14 pm 
Newbie

Joined: Fri Nov 17, 2006 1:00 pm
Posts: 6
thanks for your suggestions.. but i don't think that using those tools is something i can do right now..

i've been reading tutorials online, mainly Section 1.3 Part 2 of this one:
http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html#tutorial-associations

... and I've come up with something like this (I deleted my site_network_ref domain and xml mapping btw):

I have a networkref domain object (I call it NetworkData), and a corresponding .hbm.xml file that looks like this:

Code:
   <class name="domain.NetworkData" table="network_ref"
      proxy="domain.NetworkData" dynamic-update="true"
      dynamic-insert="true">

      <set name="siteIDLink" table="site_network_ref">
         <key column="site_id" />
         <many-to-many column="network_id"
            class="domain.SiteNetworkRef" />
      </set>

      <property name="subnetIP" type="string" column="subnet_ip" />

      <property name="subnetMask" type="string" column="subnet_mask" />

      <property name="expirationDate" column="expiration_dtm"
         type="date" update="true" insert="true" />

   </class>


and then I created a site_ref domain object (I call it Site), and a corresponding mapping that looks like this:

Code:

   <class name="domain.Site" table="site_ref"
      proxy="domain.Site" dynamic-update="true"
      dynamic-insert="true">
                  
      <property name="siteType" type="string" column="site_type" />

      <property name="wirelessIndicator" type="char" column="wireless_ind" />

      <property name="dialupIndicator" type="char" column="dialup_ind" />
      
      <property name="expirationDate" column="expiration_dtm"
         type="date" update="true" insert="true" />
      
   </class>


Now if you notice in the first one, I have a set defined, and many to many mapping.. but I dont think this is really what I want (and I dont think I did it right, regardless). Multiple network ID's can be matched to a single site id in the site_network_ref table... so I think I need a many-to-one, but I really don't understand this. I just want one mapping down solid, because I have a lot more of these to go. Thanks again for your help so far!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 2:42 pm 
Newbie

Joined: Fri Nov 17, 2006 1:00 pm
Posts: 6
I posted the old copy of my network data xml file. Sorry!

This is the set portion of it. I removed the sitenetworkref domain and xml mapping.

Code:
      <set name="siteIDLink" table="site_network_ref"> <key column="site_id" />
         <many-to-many column="network_id"
            class="domain.NetworkData" />
      </set>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.