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.