Java Reference
In-Depth Information
The any Tag
The any tag represents a polymorphic association between the attribute and several entity
classes. The mapping is expressed in the schema with a column to specify the type of the
related entity, and then columns for the identifier of the related entity.
Because a proper foreign key cannot be specified (being dependent upon multiple
tables), this is not the generally recommended technique for making polymorphic associa-
tions. When possible, use the techniques described in the previous “Mapping Inheritance
Relationships” section.
The array Tag
The array tag represents the innate array feature of the Java language. The syntax of this is
virtually identical to that used for the List collection class, and we recommend the use of
List except when primitive values are to be stored, or when you are constrained by an exist-
ing application architecture to work with arrays.
The <dynamic-component> Element
While the full-blown dynamic class approach (discussed briefly in the “Entities” section at the
beginning of the chapter) is really only suitable for prototyping exercises, the dynamic compo-
nent technique allows some of that flexibility in a package that reflects some legitimate
techniques.
The <dynamic-component> element permits you to place any of the items that can be
mapped with the normal <component> element into a map with a given key. For example,
we could obtain and combine several items of information relating to an entity's ownership
into a single Map with named elements, as follows:
<dynamic-component name="ownership">
<property name="user" type="string" column="user"/>
<many-to-one
name="person"
class="com.hibernatebook.xmlmapping.Person"
column="person_id"/>
</dynamic-component>
The code to access this information in the entity is then very familiar:
Map map = entity.getOwnership();
System.out.println(map.get("user"));
System.out.println(map.get("person"));
The output would then be as follows:
dcminter
person: { "Dave Minter", 33, "5'10" }
Search WWH ::




Custom Search