Just another site

Monthly Archives: August 2014

Bigdemical divide

I have the following code in a project:

bigdecimal1.divide(new BigDecimal(3)).setScale(2, BigDecimal.ROUND_HALF_UP);

I am getting an arithmeticException : Non-terminating decimal expansion; no exact representable decimal result

We should change the above code to:

bigdecimal1.divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP);


Hibernate extra-lazy fetching strategy

This is very useful feature. if you just want to get size of the children collections but not loading the items into memory, you can add the extra LazyCollection annotation to the field. Be aware that each request for size will trigger a sql select to the DB, so it’s only recommended for large collections.

@OrderBy("date DESC")
List books = new ArrayList();