3

I'm using micronaut-data with JDBC in on my application(no hibernate) I need to generate my primary key value using Oracle DB sequences

As per their official doc(https://micronaut-projects.github.io/micronaut-data/1.0.x/guide/#jdbc) Section:9.1.4.1 SQL Annotations

Only some of JPA annotations are supported and I didn't find @GeneratedValue and @SequenceGenerator in the list(So not sure whether these are supported or not)

Moreover the doc says,

Section 9.1.4.2 ID Generation If you wish to use sequences for the ID you should invoke the SQL that generates the sequence value and assign it prior to calling save().

So, what would be the best way to query Oracle database to get sequence value ?(As I don't have any session/entity manager here unlike JPA).

Already tried generating sequence using JPA annotations:

@GeneratedValue and @SequenceGenerator

Also using,

@GenerateValue present in micronaut-data library (io.micronaut.data.annotation.GeneratedValue)

Sample Code:

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_SEQ") @SequenceGenerator(sequenceName = "EMPLOYEE_ID_SEQ", allocationSize = 1, name = "ID_SEQ")
private Long employeeId;

Above code failed with:

Caused by: java.lang.NullPointerException: null at oracle.jdbc.driver.OraclePreparedStatement.setupDbaBindBuffers(OraclePreparedStatement.java:3194)

1 Answers1

0

Sequence generators are not supported yet but are on the TODO list

Graeme Rocher
  • 7,985
  • 2
  • 26
  • 37
  • So, what approach should you suggest for time being ? One way we found is to create an abstract repository class and using 'JdbcOperations', fire DB sequence sql to get the next sequence and set the value to my entity before calling save API. – Mohit Gupta Oct 15 '19 at 18:01