I am creating a web application using spring and hibernate. Is it possible to have multiple @ManyToOne mappings in one table that reference the same Column in another table? What I mean is
If I have these two tables
@Entity
@Table(name="AUTHOR")
public class Author{
@Id
@GeneratedValue
@Column(name="AUTHOR_ID")
private IntegerauthorId;
@Column(name="AUTHOR_NAME")
private String authorName;
...
}
and
@Entity
@Table(name="BOOK")
public class book{
@Id
@GeneratedValue
@Column(name="BOOK_ID")
private Integer bookId;
@Column(name="TITLE")
private String title;
@Column(name="PREFACE_AUTHOR")
private Author prefaceAuthor;
@Column(name="BOOK_AUTHOR")
private Author bookAuthor;
...
}
How do I do the mapping so that I can populate both PREFACE_AUTHOR and BOOK_AUTHOR from the AUTHOR table?
One Author can be both the preface and book author but there can only be one preface author and one book author per book.
Let me know if there is anything I can clarify.
Thank you for the help!
/D
You should specify that it is a many-to-one and use
@JoinColumninstead of@Column, like this: