0

In the Hibernate Layer,database column price is mapped with Double type. However due to the business logic, I have to handle empty field for the price. Not having a price and having 0.0 for price have two different meaning in the buiness logic. How to handle this?

boolean day1 = true;
boolean day2 = true;
boolean day3 = true;
boolean day4 = true;
boolean day5 = true;
boolean day6 = true;
boolean day7 = true;
//double ogPrice = 10.99;


OrderGuideProduct orderGuideProduct = new OrderGuideProduct();

orderGuideProduct.setDay1(day1);
orderGuideProduct.setDay2(day2);
orderGuideProduct.setDay3(day3);
orderGuideProduct.setDay4(day4);
orderGuideProduct.setDay5(day5);
orderGuideProduct.setDay6(day6);
orderGuideProduct.setDay7(day7);

//  this is where I need to set the empty value
orderGuideProduct.setOgPrice();
Alex Karshin
  • 12,300
  • 14
  • 50
  • 60
newday
  • 3,730
  • 9
  • 50
  • 77

2 Answers2

1

I would suggest using a BigDecimal rather than a double in this case. The former is nullable (and hence distinguishable from 0.0) and should be recognised by Hibernate.

Joe C
  • 14,676
  • 8
  • 38
  • 49
0

Having Double instead of double was helpful to me.

newday
  • 3,730
  • 9
  • 50
  • 77