如何在Spring数据-jpa -hibernate中使用复合键进行findby? @EmbeddedId

问题描述 投票:0回答:1
@Embeddable
public class AccountTransactionId implements Serializable {
    private String trxDate;
    private String acctNo;
    private int trxNo;
}

@Entity
public class Transaction {
    @EmbeddedId
    private AccountTransactionId accountTransactionId;

    private int amt;
    private int fee;
    private String cancelYn;
}

这是我的资料库。如何制作查找方法?我对此一无所知

List<Map<String, Object>> findByAccountTransactionId_trxDate(String trxDate);

我尝试过“ findByAccountTransactionId_trxDate”,“ findByAccountTransactionIdTrxDate”,“ findByIdTrxDate” ...

hibernate jpa spring-data composite-key embeddable
1个回答
0
投票

您可以这样写:

public interface TransactionRepository extends JpaRepository<Transaction, AccountTransactionId> {

    List<Map<String, Object>> findByTrxDateAndAcctNo(String trxDate, String acctNo);

}
© www.soinside.com 2019 - 2024. All rights reserved.