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();
Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
newday
  • 3,842
  • 10
  • 54
  • 79

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
  • 15,324
  • 8
  • 38
  • 50
0

Having Double instead of double was helpful to me.

newday
  • 3,842
  • 10
  • 54
  • 79