-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping Property of Type User defined Structure
PostPosted: Tue Jun 13, 2006 12:43 pm 
Newbie

Joined: Tue Jun 13, 2006 11:14 am
Posts: 2
I have a class "Invoice Line" that has two properties that are of type "User defined structure".

The first one is QuantitySold and it is a structure called Quantity with two fields (Ammount and Unit).

The other is Price one is a structure called MonetaryValue and it also has two fields (Ammount and Currency)

How can I map each of these properties (QuantitySold and Price) to four columns (Quantity, Unit, Price, Currency)?

Can you do something like this:

<property name="QuantitySold.Ammount" column="per_qty" type="Int32" access="property"/>

<property name="QuantitySold.Unit" column="per_unit" type="String" length="50" access="property"/>

Thanks in advanced!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 1:26 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
if these properties are inthe same table as the Invoice Line, you could create a Component:

Code:
<class name="InvoiceLine">
    <id>
        <generator />
    </id>

    <component name="QuanititySold" class="Quantity>
        <property name="Amount" column="per_qty" />
        <property name="Unit" column="per_unit" />
    </component>

    <component name="Price" class="MonitaryValue>
        <property name="Amount" />
        <property name="Currency" />
    </component>
</class>


obviously the mapping needs more detail. you could also create a UserDefinedType, but this seems easier to me at first blush.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 2:22 pm 
Newbie

Joined: Tue Jun 13, 2006 11:14 am
Posts: 2
Perfect!

Thank you very much, just what I was loking for.


Top
 Profile  
 
 Post subject: Maybe an another solution: the formula tag
PostPosted: Wed Jun 14, 2006 2:50 pm 
Newbie

Joined: Tue Jun 06, 2006 7:33 pm
Posts: 11
I find in the hibernate doc the tag formula, maybe it could be help you...

Quote:
<property name="totalPrice"
formula="( SELECT SUM (li.quantity*p.price) FROM LineItem li, Product p
WHERE li.productId = p.productId
AND li.customerId = customerId
AND li.orderNumber = orderNumber )"/>


the only constaint is that work only on read-only

http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-property


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