-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need a little modeling help...
PostPosted: Sat Sep 06, 2003 9:39 pm 
Newbie

Joined: Sat Sep 06, 2003 8:49 pm
Posts: 8
I have a data model that I'm trying to map. I know how to do this if I'm using straight jdbc, but being new to hibernate I'm not real sure how to do it. Any help is greatly appreciated. What I have is something like this

site
-address, city, state, zip, etc

contact
-name, email address, etc

customer
-name (string)
-contact (Set of contacts)
-site (Set of sites)

===========
I have the above set up and working with reverse one-to-many mappings.

What I want to do is add something like

service-request
-id (unique id, straight forward)
-customer (customer)
-site (Site)
-contact (Contact)

the id is simple, just use the id element with some generator.
Now how do I get the correct behaviour for mapping the customer, site and contact? I would like a table like

service-request
-id (int)
-customer_id (int)
-site_id (int)
-contact_id (int)

is there any way to do this in hibernate? It's not a one to one mapping, a site/customer/contact can be associated with more than one service request. It's not a one-to-many mapping, each service request can only have one customer/site/contact. Is this a many-to-many mapping? Thanks in advance!!!
--m


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 07, 2003 12:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I am assuming what you want in your java model is something like:
Code:
public class ServiceRequest
{
    private Long id;
    private Customer customer;
    private Contact contact;
    private Site site;
    ...
}


Then customer, contact, and site are each a many-to-one relationship. For example, a ServiceRequest can have only one Customer, but a customer can have many ServiceRequests.

Map the above like:
Code:
<class name="ServiceRequest" table="service-request">
    <id name="id" type="long">
        <generator class="..."/>
    </id>
    ...
    <many-to-one
             name="customer"
             column="customer"
             class="Customer"
    />
    <many-to-one
             name="contact"
             column="contact"
             class="Contact"
    />
    <many-to-one
             name="site"
             column="site"
             class="Site"
    />
</class>


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