Add Book.java
This commit is contained in:
37
src/main/java/com/ankurm/sdjpa4demo/domain/Book.java
Normal file
37
src/main/java/com/ankurm/sdjpa4demo/domain/Book.java
Normal 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 + "}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user