Skip to content

Instantly share code, notes, and snippets.

@dnlcorrea
Last active June 22, 2020 20:58
Show Gist options
  • Save dnlcorrea/d98fa2e630e4d7795daf5499bcad9770 to your computer and use it in GitHub Desktop.
Save dnlcorrea/d98fa2e630e4d7795daf5499bcad9770 to your computer and use it in GitHub Desktop.
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "authors")
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@ManyToMany(fetch = FetchType.LAZY)
private List<Book> books;
// Getters / Setters...
}
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "books")
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String isbn;
@ManyToMany(mappedBy = "books", fetch = FetchType.LAZY)
private List<Author> authors;
// Getters / Setters...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment