8.12.60 @TableGenerator
- Organization of this subsection
(1) Description
This annotation specifies the settings of the generator that creates the primary key.
The following settings are required when using @TableGenerator:
-
Specify GenerationType.TABLE in the strategy element of @GeneratedValue.
-
Set up the name specified in the generator element of @GeneratedValue to the name element of @TableGenerator.
The table generator is specified in the fields or properties of the entity class or primary key. The scope of the generator name is enabled in the persistence unit.
Use the rows of the generator table when generating the primary key value in an entity.
When creating a table for managing the sequence, specify a positive integer in the initial value. If 0 is specified in the initial value, the primary key will be generated from 1.
The applicable targets are class, method, and field.
(2) Element
The following table lists the elements of @TableGenerator:
Element name |
Optional/Required |
Element description |
---|---|---|
Required |
This element specifies the generator name for the primary key value. |
|
Optional |
This element specifies the name of the table that maintains the generated primary key values. |
|
catalog |
Optional |
This element specifies the catalog name of the table that maintains the generated primary key values. Note that Cosminexus JPA provider does not support this attribute. |
Optional |
This element specifies the schema name of the table that maintains the generated primary key values. |
|
Optional |
This element specifies the primary key column name of the table that maintains the generated primary key values. |
|
Optional |
This element specifies the column name that maintains the final generated value. |
|
Optional |
This element specifies the primary key value of the table that maintains the generated primary key values. |
|
initialValue |
Optional |
This element specifies the value used for initializing the column that maintains the recent generated values. Note that Cosminexus JPA provider does not support this attribute. Ignore when the value is specified. |
Optional |
This element specifies the size of allocating the primary key value from the generator. |
|
uniqueConstraints |
Optional |
This element specifies the unique key constraints in the table that maintains the generated primary key values. Note that Cosminexus JPA provider does not support this attribute. Ignore when the value is specified. |
The details of attributes that are supported with Cosminexus JPA provider are as follows:
(a) name element
- Type
-
String
- Description
-
This element specifies the generator name for the primary key value.
The value that can be specified is a character string.
- Default value
-
None
(b) table element
- Type
-
String
- Description
-
This element specifies the name of the table that maintains the generated primary key values.
The table name that can be specified depends on the database specifications.
- Default value
-
"SEQUENCE"
(c) schema element
- Type
-
String
- Description
-
This element specifies the schema name of the table that maintains the generated primary key values.
The schema name that can be specified depends on the database specifications.
- Default value
-
Default schema name of the database used
(d) pkColumnName element
- Type
-
String
- Description
-
This element specifies the primary key column name of the table that maintains the generated primary key values.
The column name that can be specified depends on the database specifications.
- Default value
-
"SEQ_NAME"
(e) valueColumnName element
- Type
-
String
- Description
-
This element specifies the column name that maintains the final generated value.
The column name that can be specified depends on the database specifications.
- Default value
-
"SEQ_COUNT"
(f) pkColumnValue element
- Type
-
String
- Description
-
This element specifies the primary key value of the table that maintains the generated primary key values.
The value that can be specified depends on the type of column of the generated primary key.
- Default value
-
Character string specified in the name element
(g) allocationSize element
- Type
-
int
- Description
-
This element specifies the allocation size of the primary key value from the generator.
The value that can be specified is a numeric value that is at least one more than the int type.
Note that you can specify the maximum value used during the execution in this element. If you specify a large value for acquiring the management area of the sequence number, the java.lang.OutOfMemoryError exception will occur during the execution.
- Default value
-
50