strategy = GenerationType.SEQUENCE depends on sequence in Oracle?

I am new in SequenceGenerator. I just wanted to know,if i am using GenerationType.SEQUENCE then we have to create sequence with name as SAMPLE_ID_SEQ?

@Id
 @SequenceGenerator(name = "SAMPLE", sequenceName = "SAMPLE_ID_SEQ", allocationSize = 1)
 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SAMPLE")
 @Column(name = "ID")

1 answer

  • answered 2018-04-17 04:52 Sr7

    Yes you will have to create a sequence in your database.

    This is what the oracle website say:

    Specifying a Sequence

    To use a specific named sequence object, whether it is generated by schema generation or already exists in the database, you must define a sequence generator using a @SequenceGenerator annotation. You may choose any unique label as the name for the sequence generator. Reference this name by the generator element in the @GeneratedValue annotation. Also, include the sequenceName element to specify the name of the database sequence object that you are using.

    If the sequence object already exists in the database, then you must specify the allocationSize to match the INCREMENT value of the database sequence object.

    You can read it here:http://www.oracle.com/technetwork/middleware/ias/id-generation-083058.html#sequence