Add Book.java

This commit is contained in:
2026-07-25 05:36:20 +00:00
parent 789e256407
commit 0ab2838dc8

View File

@@ -0,0 +1,37 @@
package com.ankurm.sdjpa4demo.domain;
import jakarta.persistence.*;
import java.math.BigDecimal;
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
private BigDecimal price;
@ManyToOne(fetch = FetchType.LAZY)
private Author author;
protected Book() { }
public Book(String title, BigDecimal price, Author author) {
this.title = title;
this.price = price;
this.author = author;
}
public Long getId() { return id; }
public String getTitle() { return title; }
public BigDecimal getPrice() { return price; }
public Author getAuthor() { return author; }
@Override
public String toString() {
return "Book{title='" + title + "', price=" + price + "}";
}
}