Java Reference
In-Depth Information
@SequenceGenerator is shared among all entities, so keep that in mind when assign-
ing internal JPA names to ensure they're unique.
Table
The table strategy uses a small database table to get auto-incrementing unique numbers.
Typically the table has two columns in it. The first column is a unique name for a sequence.
The second column is the sequence value. To configure JPA to use the table strategy, you
first need a table:
CREATE TABLE SEQUENCE_GENERATOR_TABLE (
SEQUENCE_NAME VARCHAR2(80) NOT NULL,
SEQUENCE_VALUE NUMBER(15) NOT NULL,
PRIMARY KEY (SEQUENCE_NAME));
Now that you have an empty table, the next step, shown in the following listing, is to manu-
ally insert a sequence and its initial value.
Listing 9.14. Insert the sequence name and initial value
Next, use @TableGenerator to configure a connection to the table, and then configure
@GeneratedValue to use this sequence generator. The next listing shows what the
User object would look like using the table strategy.
Listing 9.15. Table strategy
 
Search WWH ::




Custom Search