spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
765 stars 346 forks source link

Support for Oracle sequence [DATAJDBC-299] #479

Open spring-projects-issues opened 5 years ago

spring-projects-issues commented 5 years ago

Tomas-Mrazek opened DATAJDBC-299 and commented

Oracle 11g doesn't have auto increment as 12c, so the only option is to use explicit sequence (or slow trigger).

Setting up ID during BeforeSaveEvent causes this error, therefore it's not currently possible to use this library with Oracle 11g without a custom tweak. Related to DATAJDBC-256.

OJDBC driver correctly returns ID from sequence, if nextval is called in the same SQL query – according to official documentation.

I suggest to add a possibility to include name of sequence and then internally append query to insert @Id column with VALUE("LEGO_SEQ.NEXTVAL). Sequence could be configured via another annotation.

@Sequence("LEGO_SEQ")
@Table("LEGO")
public class LegoEntity {
    @Id
    Long id;
    String color;
    String shape;
}

Setting up custom ID is also not supported, so this issue is partially related to a stackoverflow question and DATAJDBC-269


5 votes, 6 watchers

kap199297 commented 2 months ago

Is there any update to have sequence support? By the way, our team is planning to migrate to spring data JDBC with the Postgres database.