Spring Data JPA通过嵌入式对象属性查找
我想编写一个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为此编写查询吗?
回答:
此方法名称应能解决问题:
Page<QueuedBook> findByBookIdRegion(Region region, Pageable pageable);
以上是 Spring Data JPA通过嵌入式对象属性查找 的全部内容, 来源链接: utcz.com/qa/422471.html