-->
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: dynamic mapping: between embed="true" and embed=&q
PostPosted: Thu Mar 03, 2005 9:20 pm 
Beginner
Beginner

Joined: Thu Apr 15, 2004 5:12 pm
Posts: 21
I'm playing around with the dynamic mapping to and from XML in 3.0 RC 1 (which is VERY nice, btw), and I have a question about whether it is possible on a many-to-one to get something other than a deep copy (embed-xml="true") or a shallow copy with just the id (embed-xml="false").

What I would like to do is get just the id and 1 other column, but I don't see how to do this.

I have the following two mappings that relate OrderItem and Product (I've omitted two other mappings because they aren't relevant to this question, which only concerns OrderItem and Product):

Code:
<hibernate-mapping>
    <class entity-name="OrderItem" table="ORDER_ITEMS">
        <id name="id" column="id" node="@id" type="string"/>
        <property name="amount" node="Amount" type="integer">
            <column name="AMOUNT"/>
        </property>
        <property name="price" node="Price" type="double">
            <column name="PRICE"/>
        </property>
        <many-to-one name="Order" entity-name="Order" node="." column="ORDER_ID"/>
        <many-to-one name="Product" entity-name="Product" node="Product/@id" column="PRODUCT_ID" cascade="save-update" embed-xml="false">
        </many-to-one>
        <set name="OrderItemDetails" table="ORDER_ITEM_DETAILS" inverse="true" cascade="all">
            <key column="ORDER_ITEM_ID"/>
            <one-to-many entity-name="OrderItemDetail" node="OrderItemDetail"/>
        </set>     
    </class>
</hibernate-mapping>


and

Code:
<hibernate-mapping>
    <class entity-name="Product" table="PRODUCTS">
        <id name="id" column="id" node="@id" type="string"/>
        <property name="name" node="Name" type="string">
            <column name="NAME"/>
        </property>
        <property name="price" node="Price" type="double">
            <column name="PRICE"/>
        </property>
        <property name="amount" node="Amount" type="integer">
            <column name="AMOUNT"/>
        </property>   
    </class>
</hibernate-mapping>


The many-to-one that joins OrderItem to Product is currently set to embed-xml="false", which outputs the following for a complete Order (which includes an OrderItem)

Code:
<Order id="97">
    <OrderDate>2009-02-03 09:11:18</OrderDate>
    <PriceTotal>69.16000000000001</PriceTotal>
    <OrderItems>
        <OrderItem id="98">
            <Amount>7</Amount>
            <Price>69.16000000000001</Price>
            <Product id="0"/>
            <OrderItemDetails>
                <OrderItemDetail id="99">
                    <ShipToLocation>2173 North First st., San Jose, CA</ShipToLocation>
                    <Amount>6</Amount>
                </OrderItemDetail>
                <OrderItemDetail id="100">
                    <ShipToLocation>2146 Wilshire Blvd., Beverley Hills, CA</ShipToLocation>
                    <Amount>1</Amount>
                </OrderItemDetail>
            </OrderItemDetails>
        </OrderItem>
    </OrderItems>
</Order>


The element I am concerted with is the Product. If I have embed-xml="true" on the many-to-one linking OrderItem to Product, then I get:

Code:
<Order id="97">
    <OrderDate>2009-02-03 09:11:18</OrderDate>
    <PriceTotal>69.16000000000001</PriceTotal>
    <OrderItems>
        <OrderItem id="98">
            <Amount>7</Amount>
            <Price>69.16000000000001</Price>
            <Product id="0">
                <Name>cheese</Name>
                <Price>9.88</Price>
                <Amount>5949</Amount>
            </Product>
            <OrderItemDetails>
                <OrderItemDetail id="99">
                    <ShipToLocation>2173 North First st., San Jose, CA</ShipToLocation>
                    <Amount>6</Amount>
                </OrderItemDetail>
                <OrderItemDetail id="100">
                    <ShipToLocation>2146 Wilshire Blvd., Beverley Hills, CA</ShipToLocation>
                    <Amount>1</Amount>
                </OrderItemDetail>
            </OrderItemDetails>
        </OrderItem>
    </OrderItems>
</Order>



Some tables in my app will have 100s of columns, which cannot all be included in the XML serialization, but I need more than just the id. What I would really like is something like the following:

Code:
<Product id="0">
    <Name>cheese</Name>
</Product>


Is there any way to accomplish this?

Thanks for any help or pointers for further investigation.


Top
 Profile  
 
 Post subject: shallow copy of the child element
PostPosted: Thu Jun 29, 2006 3:56 pm 
Newbie

Joined: Thu Jun 29, 2006 3:54 pm
Posts: 2
Did you ever figure out how to solve this problem?


Top
 Profile  
 
 Post subject: Re: shallow copy of the child element
PostPosted: Thu Jun 29, 2006 5:56 pm 
Beginner
Beginner

Joined: Thu Apr 15, 2004 5:12 pm
Posts: 21
kalman wrote:
Did you ever figure out how to solve this problem?


No, I did not determine any way to do this. In my case, I'm generating the hbm, so I eventually settled on generating only the needed properties where possible (in my case, meaning any entity that is only used as the destination of a many-to-one), and used the map implementation instead of xml and manual serialization to xml, which allows me to serialize only the desired property values when it wasn't possible to filter them at hbm generation time.

hth


Top
 Profile  
 
 Post subject: Would be great to have, all right
PostPosted: Sat Feb 24, 2007 4:15 am 
Newbie

Joined: Sun Jan 21, 2007 6:48 am
Posts: 6
Location: El Cerrito, CA
I agree that this feature would be great to have. In addition, it would solve the problem of endless recursive output if you have embed-xml=true in too many places.

Perhaps it could be implemented as embed-xml=custom, and then we could provide an element containing the fields and mappings in the desired output.

Right now it's all or nothing and it would be nice to have something more flexible.


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.