Skip to content

Instantly share code, notes, and snippets.

@Ikhiloya
Created July 28, 2018 15:08
Show Gist options
  • Select an option

  • Save Ikhiloya/66735a4e7486f0d8ad29962dac326c9e to your computer and use it in GitHub Desktop.

Select an option

Save Ikhiloya/66735a4e7486f0d8ad29962dac326c9e to your computer and use it in GitHub Desktop.
Author entity fof a one to many bidirectional relationship
@Entity
@Table(name = "Author")
public class Author implements Serializable {
@Column(name = "ID", nullable = false, length = 10)
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "FirstName")
@NotBlank(message = "Enter the author's first name")
public String firstName;
@Column(name = "LastName")
@NotBlank(message = "Enter the author's last name")
public String lastName;
@OneToMany(mappedBy = "author", fetch = FetchType.LAZY)
private Set<Book> books = new HashSet<>();
public Author() {
}
//getters and setters omitted for brevity
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment