[英]How to fix this query in hibernate?
So I have this query as below : 所以我有这个查询,如下所示:
/**
* @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);
where I am trying to select all the column in partner notification @Entity where partner id is equal with the parameter. 我试图选择合作伙伴通知@Entity中的所有列,其中合作伙伴ID与参数相等。 partner_id is a foreign key at my table so at my entities I have : partner_id是我表上的外键,因此在我的实体上,我有:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id")
private Account account;
and maybe here is the problem any way I have tried to test some idea I had but as is the first time there I could not find what's is wrong. 也许这是我尝试测试某个想法的任何方式的问题,但是就像第一次出现那样我找不到错误所在。
SO i have tried : 所以我试过了:
// /**
// * @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);
and 和
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id")
private Account account;
Try this 尝试这个
@Query(SELECT p FROM PartnerNotification p JOIN p.account acc WHERE acc.accountId = :partnerId)
Hope it helps! 希望能帮助到你!
实际上,您不需要任何自定义查询。
List<PartnerNotification> findByAccountId(Integer partnerId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.