spring jpa 针对复合主键如何通过 @Query 查询?
@Query("select count(id) from UserRecommendedEntity where id.userId = :userId and isLike = :isLike")
int countByUserIdAndIsLike(Long userId, int isLike);
上面代码ide会提示无法解析的字段 id.userId
。我的 UserRecommendedEntity 代码如下:
@Data
@Accessors(chain = true)
@Entity
@Table(name = "user_recommended")
public class UserRecommendedEntity {
@EmbeddedId
private UnionId id;
@Column(name = "is_like")
private Integer isLike;
@Column(name = "created_at")
private String createdAt;
@Data
public static class UnionId implements Serializable {
@Column(name = "user_id")
private Long userId;
@Column(name = "recommended_user_id")
private Long recommendedUserId;
}
}
无
IDE提示问题;实际代码可运行。