51 lines
1.1 KiB
Java
Executable File
51 lines
1.1 KiB
Java
Executable File
package com.ankurm.hibernatedemo.association;
|
|
|
|
import jakarta.persistence.Entity;
|
|
import jakarta.persistence.FetchType;
|
|
import jakarta.persistence.GeneratedValue;
|
|
import jakarta.persistence.GenerationType;
|
|
import jakarta.persistence.Id;
|
|
import jakarta.persistence.JoinColumn;
|
|
import jakarta.persistence.ManyToOne;
|
|
import jakarta.persistence.Table;
|
|
|
|
/** Owning side (holds the FK) of {@link AssocAuthor#getBooks()}. Docs: 12-association-mappings.md. */
|
|
@Entity
|
|
@Table(name = "assoc_book")
|
|
public class AssocBook {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
private String title;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "author_id")
|
|
private AssocAuthor author;
|
|
|
|
protected AssocBook() {
|
|
}
|
|
|
|
public AssocBook(String title, AssocAuthor author) {
|
|
this.title = title;
|
|
this.author = author;
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
public AssocAuthor getAuthor() {
|
|
return author;
|
|
}
|
|
|
|
public void setAuthor(AssocAuthor author) {
|
|
this.author = author;
|
|
}
|
|
}
|