我想编写一个Spring Data JPA存储库接口方法签名,该签名可以让我在该实体中找到具有嵌入式对象属性的实体。有人知道这是否可行吗?
这是我的代码:
@Entity
@Table(name = "BOOK_UPDATE_QUEUE", indexes = { uniqueConstraints = @UniqueConstraint(columnNames = {
"bookId", "region" }, name = "UK01_BOOK_UPDATE_QUEUE"))
public class QueuedBook implements Serializable {
@Embedded
@NotNull
private BookId bookId;
...
}
@Embeddable
public class BookId implements Serializable {
@NotNull
@Size(min=1, max=40)
private String bookId;
@NotNull
@Enumerated(EnumType.STRING)
private Region region;
...
}
public interface QueuedBookRepo extends JpaRepository<QueuedBook, Long> {
//I'd like to write a method like this, but can't figure out how to search by region,
//when region is actually a part of the embedded BookId
Page<QueuedBook> findByRegion(Region region, Pageable pageable);
}
我可以使用Spring Data为此编写查询吗?
是的,做到了。我找不到任何地方的文档。它是隐藏还是隐含在我没看见的地方?
—
CorayThan
将其转化为答案,并添加了指向参考文档相关部分的链接。
—
奥利弗·德罗博姆
findByBookIdRegion(Region region, Pageable pageable)
吗?