0

嗨,我分别在 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;
}
4

0 回答 0