jpa存储库:jpql连接查询

8e2ybdfx  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(243)

所以我有两个实体:

@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", allocationSize = 1)
    @Id
    @GeneratedValue(strategy = GenerationType.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获取这场战斗。由于solution表包含外键,所以我需要执行一个join来获取battle的细节。我对在我的战斗存储库中连接这些表所需的语法有点困惑。
我期待这样的东西:可选(battle)findbysolutionid(long solutionid);

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题