Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SpringData-jpa-hibernate中使用复合键制作findby@嵌入ID_Hibernate_Jpa_Spring Data_Composite Key_Embeddable - Fatal编程技术网

如何在SpringData-jpa-hibernate中使用复合键制作findby@嵌入ID

如何在SpringData-jpa-hibernate中使用复合键制作findby@嵌入ID,hibernate,jpa,spring-data,composite-key,embeddable,Hibernate,Jpa,Spring Data,Composite Key,Embeddable,这是我的存储库。如何制作查找方法?我对此一无所知 @Embeddable public class AccountTransactionId implements Serializable { private String trxDate; private String acctNo; private int trxNo; } @Entity public class Transaction { @EmbeddedId private AccountTr

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

@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 findbyaAccountTransactionId_trxDate(字符串trxDate);

我尝试了“FindByaAccountTransactionID_trxDate”、“FindByaAccountTransactionIDtrxDate”、“findByIdTrxDate”…

您可以这样写:

List<Map<String, Object>> findByAccountTransactionId_trxDate(String trxDate);
public interface TransactionRepository扩展了JpaRepository{
列出findBytrxDate和cctno(字符串trxDate,字符串acctNo);
}

你可以这样写:

List<Map<String, Object>> findByAccountTransactionId_trxDate(String trxDate);
public interface TransactionRepository扩展了JpaRepository{
列出findBytrxDate和cctno(字符串trxDate,字符串acctNo);
}

我建议看一下骆驼箱,看它是否会改变什么;也许正因为如此,这一切都不会起作用

其次,我希望该方法返回一个对象列表,而不是一个映射。在您的情况下,这是我期望的解决方案:

public interface TransactionRepository extends JpaRepository<Transaction, AccountTransactionId> {

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

}
public interface TransactionRepository扩展了JpaRepository{
/**
*此处将accountTransactionId重命名为id
*和trxDate到trxDate
*/
列出findByIdTrxdate(字符串trxDate、字符串acctNo);
列出findByAccountTransactionIdTrxDate(字符串trxDate,字符串acctNo);
}

我建议看一下骆驼箱,看它是否会改变什么;也许正因为如此,这一切都不会起作用

其次,我希望该方法返回一个对象列表,而不是一个映射。在您的情况下,这是我期望的解决方案:

public interface TransactionRepository extends JpaRepository<Transaction, AccountTransactionId> {

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

}
public interface TransactionRepository扩展了JpaRepository{
/**
*此处将accountTransactionId重命名为id
*和trxDate到trxDate
*/
列出findByIdTrxdate(字符串trxDate、字符串acctNo);
列出findByAccountTransactionIdTrxDate(字符串trxDate,字符串acctNo);
}
您可以使用@IdClass()

然后您可以在链接中传递示例中的类,它将是

repository.findById(新AccountId(accountno,accounttype)

这对我很有效

您可以使用@IdClass()

然后您可以在链接中传递示例中的类,它将是

repository.findById(新AccountId(accountno,accounttype)


这对我很有用

请分享你的整个存储接口请分享你的整个存储接口你是我正在等待检查的人下面的示例了解更多详细信息:-据我所知,这将引发异常,因为类型事务没有属性trxDate你是我正在等待检查的人下面的示例le了解更多详细信息:-据我所知,这将引发异常,因为类型事务没有属性TrxDate。您可以删除链接并将答案放在这里吗?您可以使用@IdClass,然后您可以在链接中传递示例中的类,它将是repository.findById(新AccountId(accountno,accounttype)这对mecan有效你可以删除链接并将答案放在这里吗?你可以使用@IdClass然后你可以在链接中传递示例中的类,它将是repository.findById(新AccountId(accountno,accounttype))这对我有效