gpt4 book ai didi

java - 如何在 hibernate 中修复此查询?

转载 作者:行者123 更新时间:2023-12-02 09:44:59 25 4
gpt4 key购买 nike

所以我有如下查询:

/**
* @param partnerId .
* @return Notification
*/
@Query("SELECT p FROM PartnerNotification p "
+ "INNER JOIN account AS account " + "WHERE account.accountId = :partnerId ")
PartnerNotification findNotificationByPartnerId(@Param("partnerId") Integer partnerId);

我试图选择合作伙伴通知@Entity中的所有列其中合作伙伴 id 等于参数。Partner_id 是我表中的外键,因此在我的实体中我有:

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id")
private Account account;

也许这就是问题所在,我试图测试我的一些想法,但就像第一次那样,我找不到问题所在。

所以我已经尝试过:

//    /**
// * @param partnerId partnerId.
// * @return PartnerNotification
// */
// PartnerNotification findNotificationByPartnerId(Integer partnerId);

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id")
private Account account;

/**
* @param partnerId .
* @return Notification
*/
@Query("SELECT p FROM PartnerNotification p "
+ "JOIN p.account acc WHERE acc.accountId = :partnerId ")
PartnerNotification findNotificationByPartnerId(@Param("partnerId") Integer partnerId);

 @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id")
private Account account;

最佳答案

试试这个

@Query(SELECT p FROM PartnerNotification p JOIN p.account acc WHERE acc.accountId = :partnerId)

希望对你有帮助!

关于java - 如何在 hibernate 中修复此查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56731792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com