gavenkoa
gavenkoa

Reputation: 48743

Length of primary key for Long data type in Java (and Hibernate)?

log(2^32) / log(10) =~ 9.63295986126
log(10^0.63295986126) / log(2) =~ 2.10264714605 > 2 bit

log(2^64) / log(10) =~  19.2659197225
log(10^0.2659197225) / log(2) =~ 0.883366197155 < 2 bit

As you can see 9 digits for Integer doesn't lead to negative values in Integer type.

But 19 digits in Long can cause sign overflow... I usually see NUMBER(18) as type of ID column...

Is it possible to have problem with mapping NUMBER(19) to Long in Hibernate?

Upvotes: 5

Views: 1736

Answers (1)

ibre5041
ibre5041

Reputation: 5288

Do not use Long - it's intended for numbers. You never multiply, add, subtract PKs. (you probably even never sort them). For Oracle datatype NUMBER use either oracle.sql.NUMBER or java.math.BigDecimal.

Upvotes: 2

Related Questions