Reputation: 649
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. partner_id is a foreign key at my table so at my entities I have :
@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;
Upvotes: 0
Views: 104
Reputation: 1528
Try this
@Query(SELECT p FROM PartnerNotification p JOIN p.account acc WHERE acc.accountId = :partnerId)
Hope it helps!
Upvotes: 1
Reputation: 9406
Actually you don't need any custom query.
List<PartnerNotification> findByAccountId(Integer partnerId);
Upvotes: 0