Book: replace BigDecimal price with embedded Money value object

This commit is contained in:
2026-07-25 08:19:45 +00:00
parent 68b40c903b
commit 9d42a42d26

View File

@@ -1,7 +1,6 @@
package com.ankurm.sdjpa4demo.domain;
import jakarta.persistence.*;
import java.math.BigDecimal;
@Entity
public class Book {
@@ -12,14 +11,16 @@ public class Book {
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)
private Author author;
protected Book() { }
public Book(String title, BigDecimal price, Author author) {
public Book(String title, Money price, Author author) {
this.title = title;
this.price = price;
this.author = author;
@@ -27,7 +28,7 @@ public class Book {
public Long getId() { return id; }
public String getTitle() { return title; }
public BigDecimal getPrice() { return price; }
public Money getPrice() { return price; }
public Author getAuthor() { return author; }
@Override