Java Reference
In-Depth Information
Table 7-5. Continued
Short Name
Description
seqhilo
Uses a sequence to efficiently generate identifiers that are unique to that data-
base. The Hibernate int , short , and long types are supported. This is not a
portable technique (see sequence , following).
sequence
Supports the sequence column type (essentially a database-enforced increment)
available in some, but not all, databases. This is, therefore, not a fully portable
option. The Hibernate int , short , and long types are supported.
uuid
Attempts to portably generate a (cross-database) unique primary key. The key is
composed of the local IP address, the startup time of the JVM (accurate to 1 4 of a
second), the system time, and a counter value (unique within the JVM). This can-
not guarantee absolutely that a given key is unique, but it will be good enough
for most clustering purposes.
The child elements of the <id> element are as follows:
(meta*, column*, type?, generator?)
While this is all rather complex, Listing 7-1 shows a typical <id> element from Chapter 3,
which illustrates the simplicity of the usual case.
Listing 7-1. A Typical <id> Element
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
n Note When the <id> element cannot be defined, a compound key can instead be defined using the
<composite-id> element. This is provided purely to support existing database schemas. A new Hibernate
project with a clean database design does not require this.
In addition to using the standard and custom generator types, you have the option of
using the special assigned generator type. This allows you to explicitly set the identifier for
the entities that you will be persisting—Hibernate will not then attempt to assign any iden-
tifier value to such an entity. If you use this technique, you will not be able to use the
saveOrUpdate() method on a transient entity—instead, you will have to call the appropriate
save() or update() method explicitly.
The <property> Element
While it is not absolutely essential, almost all classes will also maintain a set of properties in
the database in addition to the primary key. These must be defined by a <property> element
(see Table 7-6).
Search WWH ::




Custom Search