I encountered an issue regarding retrieval of 10^18 digit number using Hibernate. Although I am not entirely sure if it's an Oracle Database, Grails, Hibernate, or Java issue entirely. Considering this Grails domain class:
class Payment {
BigInteger id
BigDecimal amount
static mapping = {
id generator: "assigned"
version false
}
}
I encounter the issue through the retrieval:
Payment savePayment() {
BigInteger id = 201910151421550246D
BigDecimal amount = 100.00G
Payment payment = new Payment()
payment.id = id
payment.amount amount
payment.save(flush: true)
Payment retrievedPayment = Payment.findById(id)
println "payment.id: " + payment.id
println "payment.amount: " + payment.amount
println "retrievedPayment.id: " + retrievedPayment.id
println "retrievedPayment.amount: " + retrievedPayment.amount
// payment.id: 201910151421550246
// payment.amount: 100.00
// retrievedPayment.id: 201910151421550240
// retrievedPayment.amount: 100.00
return retrievedPayment
}
I assigned 201910151421550246 as id before saving and also confirmed it's value if its the same on the database. And it is. Also when I tried to retrieve the said record using that id, I can still retrieve the same Payment record. The problem is why the value is off by six points? I'm currently mapping it to String data type and convert it to BigInteger when I need to perform numeric operations as a temporary solution.