views:

56

answers:

1

I have a following domain model:

Entity1 -> ValueType1-> Entity2

How can I write the mapping file to represent the above situation (while retrieving Entity1)?

PS: I know I can use component tag when value type does not refer to another entity (in this case Entity2).

Thanks

+1  A: 

You can use many-to-one inside your component to reference Entity2:

<class name="Entity1" table="entities_table">
    <id name="Id" column="id" unsaved-value="0">
      <generator class="native" />
    </id>

    <component name="NameOfValueType1Property" class="ValueType1">
        <many-to-one name="NameOfEntity2Property" class="Entity2" />
    </component>
</class>

In this case Entity2 needs to be a persistent class with its own mapping file.

Darin Dimitrov