Java Reference
In-Depth Information
Attribute
Values
Default
Description
name
The name of the attribute in the class representing
this primary key. If this is omitted, it is assumed that
the class does not have an attribute directly repre-
senting this primary key. Naturally, the column attrib-
ute must be provided if the name attribute is omitted.
node
Specifies the name of the XML element or attribute
that should be used by the XML relational persist-
ence features.
type
The Hibernate type of the column.
unsaved-value
The value that the attribute should take when an
instance of the class has been created but not yet per-
sisted to the database. This attribute is mandatory.
The <id> element requires a <generator> element to be specified, which defines how to
generate a new primary key for a new instance of the class. The generator takes a class attri-
bute, which defines the mechanism to be used. The class should be an implementation of
org.hibernate.id.IdentifierGenerator . Optional <param> elements can be provided if the
identifier needs additional configuration information, each having the following form:
<param name="parameter name">parameter value</param>
Hibernate provides several default IdentifierGenerator implementations, which can be
referenced by convenient short names, as shown in Table 7-5. These are fairly comprehensive,
so you are unlikely to need to implement your own IdentifierGenerator .
Table 7-5. The Default IdentiferGenerator Implementations
Short Name
Description
guid
Uses a database-generated “globally” unique identifier. This is not portable to
databases that do not have a guid type. The specific implementation, and hence
the quality of the uniqueness of this key, may vary from vendor to vendor.
hilo
Uses a database table and column to efficiently and portably maintain and gen-
erate identifiers that are unique to that database. The Hibernate int , short , and
long types are supported.
identity
Supports the identity column type available in some, but not all, databases. This
is therefore not a fully portable option. The Hibernate int , short , and long types
are supported.
increment
Generates a suitable key by adding 1 to the current highest key value. Can apply
to int , short , or long hibernate types. This only works if other processes are not
permitted to update the table at the same time. If multiple processes are run-
ning, then depending on the constraints enforced by the database, the result
may be an error in the application(s) or data corruption.
native
Selects one of sequence , identity , or hilo , as appropriate. This is a good com-
promise option since it uses the innate features of the database and is portable
to most platforms. This is particularly appropriate if your code is likely to be
deployed to a number of database implementations with differing capabilities.
Continued
Search WWH ::




Custom Search