JPA 存储库:JPQL 加入查询

问题描述

所以我有两个实体:

@Entity
public class Battle {

    @SequenceGenerator(name = "battle_sequence",sequenceName = "battle_sequence",allocationSize = 1)
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "battle_sequence")
    @Column(name = "id",updatable = false)
    private long id;
    private String title;
    @Enumerated(EnumType.STRING)
    private BattleLevel difficulty;
    @Enumerated(EnumType.STRING)
    private Language language;
    private String prompt;
    @OnetoMany(mappedBy = "battle",cascade=CascadeType.ALL)
    private List<Solution> solutions = new ArrayList<Solution>();
    @ManyToOne
    @JoinColumn(nullable = false,name = "app_user_battle_id")
    private AppUser appUser;

@Entity
public class Solution {

    @SequenceGenerator(name = "solution_sequence",sequenceName = "solution_sequence",generator = "solution_sequence")
    @Column(name = "id",updatable = false)
    private long id;
    private String name;
    private String solution;
    @ManyToOne
    @JoinColumn(name = "battle_solution_id")
    private Battle battle;
    @ManyToOne
    @JoinColumn(name = "app_user_solution_id")
    private AppUser appUser;

我正在尝试编写自定义连接查询以根据 solutionId 获取战斗。由于解决方案表包含外键,因此我需要进行连接以获取战斗的详细信息。我对在我的战斗存储库中加入这些表所需的语法有点困惑。

我期待这样的事情: 可选(战斗)findBySolutionId(long solutionId);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)