Refer to this post for how to use JoinColumn
.
To elaborate: your Author
entity must point to a Book
entity, not to its id. That's the advantage of using JPA: you work with entities, not their keys.
Here's an example:
@Entity
@Table(name = "Book")
public class Book {
@OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="book")
private Collection<Author> authors;
// ...
}
@Entity
public class Author {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="book_id")
private Book book;
// ...
}
Why you would have one book per author (the join column points to the book here) is however questionable, you should probably rethink your data model: a many to many relationship might make more sense but you are going to need a third table for that (there are examples of how to setup your JPA entities accordingly).