0

I'm working in a project based on oracle db and JPA, I have realized that a column whose value should be generated using a sequence SEQ_CASO has a precision= 12.

enter image description here

However in the sequence object declared in Oracle db I have found the maximum number is much bigger than a 12 figures number (9999999999999...):

enter image description here

I would like to know what would happen if the records number exceeded a 12 figures number in the db? Would the precision of 12 numbers defined by JPA crush the app or something?

MT0
  • 143,790
  • 11
  • 59
  • 117

2 Answers2

1

Answering to your main question:

I would like to know what would happen if the records number exceeded a 12 figures number in the db?

Considering the code you quoted was made by reverse engineering, the column is probably defined in Oracle as NUMBER(12,0) (precision 12, scale 0).

That said, when the sequence in your application arrives to the point of generating 13 digit numbers, the Oracle database will return the following error when trying to insert these numbers in your table:

ORA-01438: value larger than specified precision allows for this column

The definition of precision and scale can be tricky in Oracle, especially when they are not explicitly defined (i.e. the col is defined just as NUMBER - no precision or scale specified).

More information about precision and scale:

What is the difference between precision and scale?

What is the default Precision and Scale for a Number in Oracle?

francisco neto
  • 797
  • 1
  • 5
  • 13
0

you don't need to define unique,nullable attributes with @Column annotation. When you define @Id annotation then it becomes primary key column which is not null and unique.

Even you don't need to define precision attribute and it works properly without it.

@Id
@SequenceGenerator(name="SEQ_CASO",sequenceName="SEQ_CASO_PK",initialValue=1500000,allocationSize=1)
@GeneratedValue(generator="SEQ_CASO",strategy=GenerationType.Sequence)
@Column("ID")
private long Id;
Nafaz M N M
  • 1,558
  • 2
  • 27
  • 41
  • Thanks Nafaz , this code i'm working on, is from an existing project and i do think it was made by reverse engineering of the database table. but what i need to know what would happen if the generated id exceeded a number with the defined precision ? –  Sep 19 '20 at 14:18