2015-12-15 56 views
1

我有一個如下所示的控制器。彈出數據JPA過濾

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

的AccountEntity是如下

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>(); 

我爲idaccountType其易於使用findByIdAndAccountType()方法過濾,並自動生成查詢。

但是如果我想使用idname這是Plan (AccountEntity.PlanEntity.name)屬性過濾,它不是簡單的,因爲name是從子表。我如何處理這個標準?

+0

您可以註釋方法'方法之一以下注釋findByIdAndPlanEntityName 'AccountEntityRepository'中使用JPQL或連接AccountEntity和PlanEntity的SQL查詢,並返回符合條件的AccountEntity對象列表。這可能會幫助您http://www.oracle.com/technetwork/articles/vasiliev-jpql-087123.html。 – Vikdor

回答

2

假設PlanEntity和TransactionEntryEntity是由@OneToOne或@OneToMany等

你可以做在AccountEntity

的倉庫
@Query("select a from AccountEntity a where a.planEntity.name = :name") 
public aMethod(@Param("name") String name)