我分别在BookEO和BookAreaEO类中有这样的关系。现在,我想了解mappedBy的目的是什么以及如何使用JPA在BookEO中编写如下所示的查询
select * from book b where exists (
select book_id from book_report_area ba
where b.book_id = ba.book_id and ba.subject_area_id=200);
// BookEO.java
Set<BookArea> bookAreas;
@Override
@PrivateOwned
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "book", targetEntity = BookAreaEO.class, orphanRemoval = true)
public Set<BookArea> getBookAreas() {
return bookAreas;
}
// BookAreaEO.java
Book book;
@Override
@ManyToOne(fetch = FetchType.LAZY, targetEntity = BookEO.class, optional = false)
@JoinColumn(name = "BOOK_ID", nullable = false)
public Book getBook() {
return book;
}