The
<property> element declares a persistent,
JavaBean style property of the class.
| <property |
| |
name="propertyName"
column="column_name"
type="typename"
update="true|false"
insert="true|false"
formula="arbitrary SQL expression"
access="field|property|ClassName"
lazy="true|false"
unique="true|false"
not-null="true|false"
optimistic-lock="true|false"
|
(1)
(2)
(3)
(4)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
|
| /> |
All
generators implement the interface org.hibernate.id.IdentifierGenerator.
This is a very simple interface; some applications
may choose to provide their own specialized
implementations. However, Hibernate provides
a range of built-in implementations. There
are shortcut names for the built-in generators:
| (1) |
name:
the name of the property, with an
initial lowercase letter. |
| (2) |
column
(optional - defaults to the property
name): the name of the mapped database
table column. This may also be specified
by nested <column> element(s).
|
| (3) |
type
(optional): a name that indicates
the Hibernate type. |
| (4) |
update,
insert (optional - defaults to true)
: specifies that the mapped columns
should be included in SQL UPDATE and/or
INSERT statements. Setting both to
false allows a pure "derived"
property whose value is initialized
from some other property that maps
to the same colum(s) or by a trigger
or other application. |
| (5) |
formula
(optional): an SQL expression that
defines the value for a computed property.
Computed properties do not have a
column mapping of their own. |
| (6) |
access
(optional - defaults to property):
The strategy Hibernate should use
for accessing the property value.
|
| (7) |
lazy
(optional - defaults to false): Specifies
that this property should be fetched
lazily when the instance variable
is first accessed (requires build-time
bytecode instrumentation). |
| (8) |
unique
(optional): Enable the DDL generation
of a unique constraint for the columns.
Also, allow this to be the target
of a property-ref. |
| (9) |
not-null
(optional): Enable the DDL generation
of a nullability constraint for the
columns. |
| (10) |
optimistic-lock
(optional - defaults to true): Specifies
that updates to this property do or
do not require acquisition of the
optimistic lock. In other words, determines
if a version increment should occur
when this property is dirty. |
typename could be:
- The
name of a Hibernate basic type
(eg. integer, string, character,
date, timestamp, float, binary,
serializable, object, blob).
- The
name of a Java class with a default
basic type (eg. int, float, char,
java.lang.String, java.util.Date,
java.lang.Integer, java.sql.Clob).
- The
name of a serializable Java class.
- The
class name of a custom type (eg.
com.illflow.type.MyCustomType).
|
An especially powerful feature are derived
properties. These properties are by definition
read-only, the property value is computed
at load time. You declare the computation
as a SQL expression, this translates to
a SELECT clause subquery in the SQL query
that loads an instance:
<property
name="totalPrice"
formula="( SELECT SUM (li.quantity*p.price)
FROM LineItem li, Product p |
| |
WHERE
li.productId = p.productId
AND li.customerId = customerId
AND li.orderNumber = orderNumber )"/> |
|