Book: replace BigDecimal price with embedded Money value object
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package com.ankurm.sdjpa4demo.domain;
|
package com.ankurm.sdjpa4demo.domain;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Book {
|
public class Book {
|
||||||
@@ -12,14 +11,16 @@ public class Book {
|
|||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
private BigDecimal price;
|
// Money's fields become columns on the book table: amount -> price_amount, currency -> price_currency.
|
||||||
|
@Embedded
|
||||||
|
private Money price;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private Author author;
|
private Author author;
|
||||||
|
|
||||||
protected Book() { }
|
protected Book() { }
|
||||||
|
|
||||||
public Book(String title, BigDecimal price, Author author) {
|
public Book(String title, Money price, Author author) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.price = price;
|
this.price = price;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
@@ -27,7 +28,7 @@ public class Book {
|
|||||||
|
|
||||||
public Long getId() { return id; }
|
public Long getId() { return id; }
|
||||||
public String getTitle() { return title; }
|
public String getTitle() { return title; }
|
||||||
public BigDecimal getPrice() { return price; }
|
public Money getPrice() { return price; }
|
||||||
public Author getAuthor() { return author; }
|
public Author getAuthor() { return author; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user