5
 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?

4
  • Can not understand: how length of column in table in oracle influences on possibility of gaining negative numbers in ID from Hibernate? Commented Mar 5, 2013 at 13:07
  • log(9'999'999'999'999'999'999) / log(2) =~ 63.1166338029 so you can't hold this value in 63 bits (note there are 19 of 9). So sign bit will be used... And possibly Hibernate throw error. That is a question... Commented Mar 5, 2013 at 13:13
  • Ok, that's an answer: sign bit could be used. So what's the question? Commented Mar 5, 2013 at 13:18
  • I am not native English speaker: Is it possible to have problem with mapping NUMBER(19) to Long in Hibernate? Commented Mar 5, 2013 at 13:23

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hm... Never use String because I never concatenate/search them. But you are right that for big NUMBER I have to use java.math.BigDecimal for id field! +1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.