diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java b/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java index 0bbccfe..aa3f1a7 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java @@ -2,6 +2,8 @@ package com.fjordtek.bookstore; +import java.math.BigDecimal; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; @@ -41,7 +43,7 @@ public class BookstoreApplication extends SpringBootServletInitializer { "Angela Carter", 1979, "1231231-12", - 18.00, + new BigDecimal("18.00"), categoryRepository.findByName("Horror").get(0) )); bookRepository.save(new Book( @@ -49,7 +51,7 @@ public class BookstoreApplication extends SpringBootServletInitializer { "Andrzej Sapkowski", 1999, "3213221-3", - 19.99, + new BigDecimal("19.99"), categoryRepository.findByName("Fantasy").get(0) )); diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java index 43c58f6..6b94def 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java @@ -2,6 +2,8 @@ package com.fjordtek.bookstore.model; +import java.math.BigDecimal; + import javax.persistence.Column; //import java.sql.Timestamp; @@ -149,8 +151,7 @@ public class Book { @DecimalMax( value = maxPrice, message = "Too high price value. Maximum allowed: " + maxPrice ) - // TODO: Use BigDecimal to keep exact precision? - private double price; + private BigDecimal price; @ManyToOne( //fetch = FetchType.LAZY, @@ -188,7 +189,7 @@ public class Book { this.isbn = isbn; } - public void setPrice(double price) { + public void setPrice(BigDecimal price) { this.price = price; } @@ -221,7 +222,7 @@ public class Book { return isbn; } - public double getPrice() { + public BigDecimal getPrice() { return price; } @@ -234,7 +235,7 @@ public class Book { public Book() {} - public Book(String title, String author, int year, String isbn, double price, Category category) { + public Book(String title, String author, int year, String isbn, BigDecimal price, Category category) { // super(); this.title = title; this.author = author;