我有一个表export const environment = {
production: false,
BASE_TEMPLATE_PATH: 'absolute/path/to/template/file'
};
和bookreservation
,我必须在提供的日期获取保留的书籍详细信息。我在book
表中有reservation_date
和expiration_date
。我正在使用bookreservation
尝试以下自定义查询:
CRUD/JPA Repository
但我收到的错误是:
@Query("from book b where b.bookid in (select br.book_bookid from bookreservation br where br.reservation_date <=:providedDate and br.expiration_date >=:providedDate)")
public Iterable<Book> findByReservationDateLessThanAndByExpirationDateGreaterThan(Date providedDate);
请建议我如何使用此获取这些详细信息。
我们可以使用这样的方法:Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: book is not mapped [from book b where b.bookid in (select br.book_bookid from br_reservation br where br.reservation_date <=:providedDate and br.expiration_date >=:providedDate)]
?
答案 0 :(得分:0)
你应该使用&#39;加入&#39;在查询中并更正JPQL。像这样:
@Query("select b from BookReservation br join br.book b where br.reservationDate <= ?1 and br.expirationDate >= ?2")
List<Book> findReserved(LocalDate reservationDate, LocalDate expirationDate );
它假设你正在使用这样的实体:
@Entity
@Table(name="book")
public class Book {
//...
}
@Entity
@Table(name="bookreservation")
public class BookReservation {
//...
@ManyToOne
private Book book;
private LocalDate reservationDate;
private LocalDate expirationDate;
//...
}