Spring Data JPA通过嵌入对象属性查找 [英] Spring Data JPA find by embedded object property
本文介绍了Spring Data JPA通过嵌入对象属性查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个Spring Data JPA存储库接口方法签名,它可以让我在该实体中找到具有嵌入对象属性的实体。有谁知道这是否可能,如果可能的话?
I want to write a Spring Data JPA repository interface method signature that will let me find entities with a property of an embedded object in that entity. Does anyone know if this is possible, and if so how?
这是我的代码:
@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为此编写查询吗? / p>
Can I write a query for this using Spring Data?
推荐答案
这个方法名称可以解决问题:
This method name should do the trick:
Page<QueuedBook> findByBookIdRegion(Region region, Pageable pageable);
关于查询推导参考文档。
这篇关于Spring Data JPA通过嵌入对象属性查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文