在SpringBoot中使用JPA [英] Usage of JPA in SpringBoot

查看:69
本文介绍了在SpringBoot中使用JPA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了此查询,但是我不确定是否存在不使用本机查询的方法.我需要找到正在使用此特定价目表的团队计划订阅(smsplan)的数量.

I made this query but I'm not sure if there's a way not to use native query. I need to find the count of the team plan subscription (of an smsplan) that is using this certain outgoing rate card.

String fetchTotalTeamPlanSubscriptionByOutgoingRateCard = "SELECT count(*) FROM team_plan_subscription WHERE plan_id IN " +
        "(SELECT sms_plan.id FROM sms_plan sms_plan INNER JOIN outgoing_sms_rate_card rate_card " +
        "ON rate_card.id = sms_plan.outgoing_sms_rate_card_id" +
        " WHERE sms_plan.outgoing_sms_rate_card_id = :outgoingSmsRateCardId);";

@Query(value = fetchTotalTeamPlanSubscriptionByOutgoingRateCard, nativeQuery = true)
public long fetchTotalTeamPlanSubscriptionByOutgoingRateCard(long outgoingSmsRateCardId);

我尝试了这个,但是似乎没有用 public long countTeamPlanSubscriptionByPlan_Id_OutgoingSmsRateCardId(longendingSmsRateCardId);

I tried this but it seems it's not working public long countTeamPlanSubscriptionByPlan_Id_OutgoingSmsRateCardId(long outgoingSmsRateCardId);

我收到错误消息无法解析属性

这是实体

public class TeamPlanSubscription {
@ManyToOne(targetEntity = SmsPlan.class, fetch = FetchType.LAZY)
    SmsPlan plan;
}

public class SmsPlan {

    @Id
    @Getter
    @Setter
    private Long id;

    @Getter
    @Setter
    @ManyToOne(targetEntity = OutgoingSmsRateCard.class, fetch = FetchType.LAZY)
    private OutgoingSmsRateCard outgoingSmsRateCard;
}

public class SmsPlan {

    @Id
    @Getter
    @Setter
    private Long id;

    @Getter
    @Setter
    @ManyToOne(targetEntity = OutgoingSmsRateCard.class, fetch = FetchType.LAZY)
    private OutgoingSmsRateCard outgoingSmsRateCard;
}

public class OutgoingSmsRateCard {

    @Id
    @Getter
    private Long id;

}

推荐答案

复制模型

Replicating your model as follows (correct me if I got something wrong when reading your question):

订阅>计划>价目表

Subscription > Plan > RateCard

使用SubscriptionRepository中的此方法可以计算具有相同价目表ID的计划的订阅数:

The number of subscriptions having plans with the same rate-card-id can be counted with this method in the SubscriptionRepository:

public long countByPlanRateCardId(long rateCardId);

您的存储库中很可能有一些错字(那里可能有一些不必要的 _id _ ).

Most probably there was some typo in your repository (might be some unnecessary _id_ in there).

官方文档: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories

这篇关于在SpringBoot中使用JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆