selects the just-inserted row to determine the
column value assigned by the database. The correct row is located using a unique
key of the entity, either:
The second approach is provided for backward compatibility with older versions of Hibernate.
This generator is intended for use with primary keys assigned by a database trigger or something similar, for example:
@Entity @Table(name="TableWithPKAssignedByTrigger")
@GenericGenerator(name = "triggered", type = SelectGenerator.class)
public class TriggeredEntity {
@Id @GeneratedValue(generator = "triggered")
private Long id;
@NaturalId
private String name;
...
}
However, after a very long working life, this generator is now handing over its
work to org., and the
above code may be written as:
@Entity @Table(name="TableWithPKAssignedByTrigger")
public class TriggeredEntity {
@Id @Generated
private Long id;
@NaturalId
private String name;
...
}
For tables with identity/autoincrement columns, use IdentityGenerator.
The actual work involved in retrieving the primary key value is the job of
org..
Arguably, this class breaks the natural separation of responsibility between the generator and the coordinating code, since its role is to specify how the generated value is retrieved.
Implementation Note
This also implements the select generation type in hbm.xml mappings.
org.hibernate.annotations.NaturalId , org.hibernate.id.insert.UniqueKeySelectingDelegate
| Modifier and Type | Field and Description |
|---|---|
| public static final String | KEY
The property specifying the unique key name. |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | configure(Type
The id property type descriptor type, Properties param values, keyed by parameter name parameters, ServiceRegistry Access to service that may be needed. serviceRegistry)Overrides default org. |
| public String[] | getReferencedColumnValues(Dialect
The SQL dialect, allowing generation of an expression
in dialect-specific SQL. dialect)Implements org. |
| public String[] | getUniqueKeyPropertyNames(EntityPersister persister)
Overrides default org. inserted
row containing the generated value.
|
| public boolean | referenceColumnsInSql(Dialect dialect)
Implements org. insert or update statement.
|
| KEY | back to summary |
|---|---|
| public static final String KEY The property specifying the unique key name. | |
| uniqueKeyPropertyName | back to summary |
|---|---|
| private String uniqueKeyPropertyName | |
| SelectGenerator | back to summary |
|---|---|
| public SelectGenerator() | |
| configure | back to summary |
|---|---|
| public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) Overrides default org. Doc from org. Noop default implementation. May be overridden by subtypes.
| |
| getReferencedColumnValues | back to summary |
|---|---|
| public String[] getReferencedColumnValues(Dialect dialect) Implements org. Doc from org. A SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement. The SQL expressions might be:
| |
| getUniqueKeyPropertyNames | back to summary |
|---|---|
| public String[] getUniqueKeyPropertyNames(EntityPersister persister) Overrides default org. Doc from org. The name of a property of the entity which may be used to locate the just-
The default implementation uses the
| |
| referenceColumnsInSql | back to summary |
|---|---|
| public boolean referenceColumnsInSql(Dialect dialect) Implements org. Doc from org. Determines if the columns whose values are generated are included in the column list
of the SQL
| |