<?xml version="1.0" ?>
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
                           "http://castor.org/mapping.dtd">
<mapping>

  <!--  Mapping for ProductGroup  -->
  <class name="myapp.ProductGroup"
         identity="id">
    <description>Product group</description>
    <map-to table="prod_group" xml="group" />
    <field name="id">
      <sql/>
      <xml node="attribute"/>
    </field>
    <field name="name">
      <sql dirty="check" />
      <xml node="text" />
    </field>
  </class>


  <!--  Mapping for Product  -->
  <class name="myapp.Product"
         identity="id">
    <description>Product definition</description>
    <map-to table="prod" xml="product" />
    <field name="id">
      <sql name="id" />
      <xml name="id" node="attribute"/>
    </field>
    <field name="name">
      <sql name="name" />
      <xml name="name" node="element" />
    </field>
    <field name="price" type="float">
      <sql name="price" type="double" />
      <xml name="price" node="element" />
    </field>

    <!--  Product has reference to ProductGroup,
          many products may reference same group  -->
    <field name="group" type="myapp.ProductGroup">
      <sql name="group_id" />
      <xml name="group" node="element" />
    </field>

    <!-- Product has reference to ProductDetail
         many details per product  -->
    <field name="detail" type="myapp.ProductDetail" required="true"
           collection="enumerate">
      <xml name="detail" node="element" />
    </field>

    <!-- Product has reference to Category with
         many-many relationship -->
<!--
    <field name="category" type="myapp.Category" required="true"
           collection="enumerate">
      <sql name="category_id"
           many-table="category_prod" many-key="prod_id" />
      <xml name="category" node="element" />
    </field>
-->

  </class>


  <!--  Mapping for Computer, extending Product  -->
  <class name="myapp.Computer" extends="myapp.Product">
    <description>Computer definition, extends generic product</description>
    <map-to table="computer" xml="computer" />
    <field name="cpu">
      <sql/>
      <xml node="element" />
    </field>
  </class>


  <!--  Mapping for Product Detail -->
  <class name="myapp.ProductDetail" identity="id">
    <description>Product detail</description>
    <map-to table="prod_detail" xml="detail" />
    <field name="id">
      <sql/>
      <xml node="attribute"/>
    </field>
    <field name="product" type="myapp.Product">
      <sql name="prod_id" />
      <xml name="product" node="element" />
    </field>
    <field name="name">
      <sql/>
      <xml node="text" />
    </field>
  </class>


  <!--  Mapping for Category  -->
  <class name="myapp.Category" identity="id">
    <description>A product category, any number of products can belong to
                 the same category, a product can belong to any number of
                 categories</description>
    <map-to table="category" xml="category" />
    <field name="id">
      <sql/>
      <xml/>
    </field>
    <field name="name">
      <sql/>
      <xml node="element" />
    </field>
<!--
    <field name="product" type="myapp.Product" required="true"
           collection="enumerate">
      <sql name="prod_id"
           many-table="category_prod" many-key="category_id" />
      <xml name="product" node="element" />
    </field>
-->
  </class>


</mapping>

