0

I have an entity class Content and I'm using a sequence generator to generate the id automatically.

@Entity
@Table(name = "CONTENT")
public class Content {
    @Id
    @Column(name = "ID", unique = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SEQ_C")
    @SequenceGenerator(name = "SEQ_C", sequenceName = "SEQ_INCREMENTER_CONTENT", allocationSize = 1)
    private Long id;
}

I'm inserting data with a saveAll() using spring boot JPA.

contentRepository.saveAll(contents);

I'm generating the table using liquibase.

<createSequence sequenceName="SEQ_INCREMENTER_CONTENT" cycle="false" minValue="1" startValue="1" incrementBy="1"/>
<createTable tableName="content">
        <column defaultValueSequenceNext="SEQ_INCREMENTER_CONTENT" name="id" type="BIGINT">
            <constraints nullable="false" primaryKey="true" primaryKeyName="pk_content"/>
    </column>
    <column name="content_type" type="VARCHAR(255)"/>
    <column name="content_type_id" type="INT"/>
    <column name="data" type="VARCHAR2(255)"/>
    <column name="placement" type="INT"/>
    <column name="placement_id" type="INT"/>
    <column name="segment_id" type="BIGINT"/>
</createTable>
<addForeignKeyConstraint baseColumnNames="segment_id" baseTableName="content" constraintName="FK_CONTENT_ON_SEGMENT" referencedColumnNames="id" referencedTableName="segment"/>

When I insert the data, spring boot JPA gives me the following error.

Caused by: oracle.jdbc.OracleDatabaseException: ORA-02201: sequence not allowed here

Also, I tried the other generation strategies as GenerationType.IDENTITY, GenerationType.AUTO and GenerationType.SEQUENCE. Still, I'm having the issue. What can I do?

codebot
  • 2,540
  • 3
  • 38
  • 89

1 Answers1

0

If you're on version 11 or lower, check this answer

If DB-version is 12 or above you may use identity column feature as described here

This is how you can check DB-version you're on

select version
  from v$instance;

or

select *
  from v$version;
ekochergin
  • 4,109
  • 2
  • 12
  • 19
  • 1
    "*Using sequences is not allowed in oracle's default column setting*" - yes it is, since 12.2 (so for all supported versions) –  Aug 10 '21 at 05:55
  • @a_horse_with_no_name never knew that. thanks! Will update my answer shortly – ekochergin Aug 10 '21 at 06:01