Spring Data JPA过滤

时间:2015-12-15 00:27:11

标签: java jpa spring-boot spring-data-jpa

我有一个控制器,如下所示。

delete object["key-1"]["inner_key_obj-2"];

AccountEntity如下

public String getAccountsFilter(
    @PathVariable("cardHolderId") String cardHolderId,
    @RequestParam(value = "accountType", required = false) String accountType,
    @RequestParam(value = "name", required = false) String name)

我对public class AccountEntity implements Serializable { private static final long serialVersionUID = 1L; private String id; private String accounttype; private Date endDate; private boolean active; private PlanEntity planEntity; private Set<TransactionEntryEntity> transactionEntry = new HashSet<TransactionEntryEntity>(); id进行了过滤,这很容易使用accountType方法,并且会自动生成查询。

但是,如果我想使用findByIdAndAccountType()id属性name进行过滤,那么由于Plan (AccountEntity.PlanEntity.name)来自子表,因此并不简单。我该如何处理这个标准?

1 个答案:

答案 0 :(得分:2)

假设由@OneToOne或@OneToMany等注释了PlanEntity和TransactionEntryEntity

您可以在AccountEntity

存储库中的某个方法中执行以下操作
@Query("select a from AccountEntity a where a.planEntity.name = :name")
public aMethod( @Param("name") String name)