javaoracle11gspring-data-jpadatabase-sequence

Is it OK to add @Id to an entity which mapped to a table without Primary key column in Spring boot Jpa?


I've started working on a legacy oracle database and using Spring boot Jpa trying to insert a new row in a table (CHANNELMGR_REQUEST) without Identity:

enter image description here

This table has a Numeric column (CM_ISN) and logically could be an Identity candidate, but I could not touch the database for some reason.

I found an existing sequence (CHANNELMGR_SEQ) that is used for generating value for that CM_ISN column too.

enter image description here

So I decided to use that sequence and added some annotation in my equivalent POJO as follow and mapped to the sequence to that CM_ISN column. But not touching the database :

enter image description here

My repository is like this :

enter image description here

While inserting the row, sucessfully invoke the sequence but get exception as bellow :

enter image description here

My questions :

  1. Is it wrong to modify an entity and add @Id to that which is not in in equivalent table?
  2. What's wrong with my code that i get error?

PS: I'm sorry for putting images instead of actual source codes, The reason is because development machine has no access to the internet.


Solution

    1. It's wrong if it is not the primary key
    2. Use BigDecimal instead of Number