Java Reference
In-Depth Information
A typical implementation of the mapping is as follows:
<map name="map" table="namemap">
<key column="fooid"/>
<index column="name" type="string"/>
<element column="value" type="string" not-null="true"/>
</map>
The bag Collection
If your class represents data using a class derived from the
List
interface, but you do not want
to maintain an index column to keep track of the order of items, you can optionally use the
bag
collection mapping to achieve this. The order in which the items are stored and retrieved
from a
bag
is completely ignored.
Although the
bag
's table does not contain enough information to determine the order of
its contents prior to persistence into the table, it
is
possible to apply an
order by
clause to the
SQL used to obtain the contents of the
bag
so that it has a natural sorted order as it is acquired.
This will not be honored at other times during the lifetime of the object.
If the
<bag>
elements lack a proper key, there will be a performance impact that will mani-
fest itself when update or delete operations are performed on the contents of the
bag
.
In addition to the common collection mappings, the
<bag>
element therefore offers the
order-by
as well as the
inverse
attribute, as shown in Table 7-15.
Table 7-15.
The Additional
<bag>
Attributes
Attribute
Values
Default
Description
inverse
true
,
false
false
Specifies that an entity is the opposite navigable end of
a relationship expressed in another entity's mapping
order-by
Specifies an arbitrary SQL
order by
clause to constrain
the results returned by the SQL query that populates the
collection
The child elements of the
<bag>
element are as follows:
(meta*,
subselect?,
cache?,
synchronize*,
comment?,
key,
(element | one-to-many | many-to-many |
composite-element | many-to-any),
loader?,
sql-insert?,
sql-update?,
sql-delete?,
sql-delete-all?,
filter*)
Search WWH ::
Custom Search