-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping Query - which type to use?
PostPosted: Thu Dec 25, 2008 7:45 pm 
Beginner
Beginner

Joined: Fri Jun 01, 2007 4:55 pm
Posts: 24
I was reading through the manual/online docs but am unsure how to map this scenario, and hoped someone could help.

I have an Order class, and this order has two addresses (address class). One is a billing address and the other is delivery address. The address table has a discriminator column differentiating between the two.


Code:
interface IOrder
{
  double Price { get; set; }
  etc...

  IAddress BillingAddress { get; set; }
  IAddress DeliveryAddress { get; set; }

}


The address table has two relevant columns, the OrderID - which order the addresses relate to, and the Type (discriminator) - billing or delivery addresses. Each other has one or two addresses (Delivery Address is optional). There should never be two billing addresses for an order, they are 1 to 1 mappings.

Can anyone help me out with the suitable mapping please?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 26, 2008 10:18 am 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
Hello, you could use a mapping like this,

Code:
<class name="order">

    <bag name="shippingAddresses" table="ShippingAddress">
        <key column="orderId"/>
        <component class="Address">

                 <!-- Address Info -->

        </component>
    </bag>

    <component name="billingAddress" required="true" class="Address">

                 <!-- Address Info -->
         
    </component>

    <!-- Other Order Info -->

</class>



regards,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 26, 2008 9:54 pm 
Beginner
Beginner

Joined: Fri Jun 01, 2007 4:55 pm
Posts: 24
Thanks for the reply. I should clarify there is only every one address per billing and delivery.

The addresses are both stored in the same table, "addresses" and there is the "Type" column to distinguish which is which. (billing/delivery)

Bags are for collections? Though I may have confused things with the number of addresses before. Each has one. So the definition of an IOrder has two properties of IAddress containing either null, or an class implementing IAddress.

With your sample for billing address component, I am not sure how that links to the address table (and gets the correct address based on OrderID and Type. Please could you clarify.

Many thanks

Simon


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 27, 2008 1:14 pm 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
What i'm trying to do with this mapping it's that the Billing Address 1:1 it's stored directly in the Orders Table and the Shipping address because it's an 1:n be stored in it's own table ShippingAddresses.

The <bag> represents an unindexed collection. I kinda prefer this kinds on collections instead of the <list> because for the list needs an extra column in the table to store the index of the list,


I hope this clarify the things a little bit,

regards,


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 27, 2008 1:29 pm 
Beginner
Beginner

Joined: Fri Jun 01, 2007 4:55 pm
Posts: 24
Thanks,

Trouble is the database is already defined :-)

There is 1:1 on both billing and delivery addresses so the interface IOrder works (it has two IAddress objects)

I guess what I want is a 1-2-1 mapping, but I'm not sure how to use the discriminator to differentiate the address types.

Cheers

Simon


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