This annotation defines a primary key generator that may be
referenced by name when a generator element is specified for
the {@link GeneratedValue} annotation. A table generator
may be specified on the entity class or on the primary key
field or property. The scope of the generator name is global
to the persistence unit (across all generator types).
Example 1:
@Entity public class Employee {
...
@TableGenerator(
name="empGen",
table="ID_GEN",
pkColumnName="GEN_KEY",
valueColumnName="GEN_VALUE",
pkColumnValue="EMP_ID",
allocationSize=1)
@Id
@GeneratedValue(strategy=TABLE, generator="empGen")
public int id;
...
}
Example 2:
@Entity public class Address {
...
@TableGenerator(
name="addressGen",
table="ID_GEN",
pkColumnName="GEN_KEY",
valueColumnName="GEN_VALUE",
pkColumnValue="ADDR_ID")
@Id
@GeneratedValue(strategy=TABLE, generator="addressGen")
public int id;
...
}
|