This version of the manual is outdated. For the latest version, follow this link: http://www.jooq.org/doc/3.0/manual.

The jOOQ User Manual. Multiple Pages : Meta model code generation : Sequences and Serialsprevious : next

# Sequences as a source for identity values

Sequences implement the org.jooq.Sequence interface, providing essentially this functionality:

// Get a field for the CURRVAL sequence property
Field<T> currval();

// Get a field for the NEXTVAL sequence property
Field<T> nextval();

So if you have a sequence like this in Oracle:

CREATE SEQUENCE s_author_id

This is what jOOQ will generate:

public final class Sequences {

    // A static sequence instance
    public static final Sequence<BigInteger> S_AUTHOR_ID = // [...]
}

Which you can use in a select statement as such:

Field<BigInteger> s = Sequences.S_AUTHOR_ID.nextval();
BigInteger nextID   = create.select(s).fetchOne(s);

Or directly fetch currval() and nextval() from the sequence using the Factory:

BigInteger currval = create.currval(Sequences.S_AUTHOR_ID);
BigInteger nextval = create.nextval(Sequences.S_AUTHOR_ID);

The jOOQ User Manual. Multiple Pages : Meta model code generation : Sequences and Serialsprevious : next

Fork me on GitHub
The jOOQ Logo