The <generatedKey> Element
The <generatedKey> element is used to specify properties for auto generated keys (from identity field or sequences). If you specify this element, MyBatis Generator (MBG) will generate an appropriate <selectKey> element inside the generated <insert> element in the SQL map. This element is an optional child element of the <table> element.
Required Attributes
Attribute | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
column | The column name of the generated column. | ||||||||||||||||||||
sqlStatement | The SQL statement that will return the new value. If this is
an identity column, then you can use one of the predefined
special values, or substitute the proper statement for your database.
The predefined special values are as follows:
|
Optional Attributes
Attribute | Description |
---|---|
identity | If true, then the column is flagged as an identity column and the
generated <selectKey> element will be placed
after the insert (for an identity column). If false, then
the generated <selectKey> will be placed before the insert
(typically for a sequence).
Important: Even if you specify the type attribute as "post", you should still specify this value as "true" for identity columns. This will flag MBG to remove the column from the insert list. The default is false. |
type | If specified, then this value will be added as the type of the generated <selectKey> element.
The value of this property should be either "pre" or "post".
Important: if a value is specified for this attribute, then the generated <selectKey> element will always be placed before the insert statement. |