Please understand that English is poor.
I want to get the SQL to join Summoner, summoner_match and match using JPASQLQuery class.
like this.
SELECT *, row_number()OVER() FROM summoner s LEFT OUTER JOIN summoner_match sm on s.account_id= sm.account_id LEFT OUTER JOIN match m on sm.game_id = m.game_id I add my source code below.
package gg.om.omgg.domain.summoner; import gg.om.omgg.domain.match.Match; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import javax.persistence.*; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @Getter @NoArgsConstructor @Entity public class Summoner implements Serializable { @Id@Column(length=56) private String id; @Column(name="account_id", length=56) private String accountId; private int profileIconId; private long revisionDate; private String name; @Column(length=78) private String puuid; private long summonerLevel; @OneToMany @JoinTable(name="summoner_match", joinColumns = @JoinColumn(name="account_id"), inverseJoinColumns = @JoinColumn(name="game_id") ) private List<Match> matches = new ArrayList<>(); //... } package gg.om.omgg.domain.match; import gg.om.omgg.domain.participant.Participant; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import javax.persistence.*; import java.util.ArrayList; import java.util.List; @Getter @NoArgsConstructor @Entity public class Match { @Id @Column(name="game_id") private long gameId; private int queueId; private String platformId; private int seasonId; private long gameCreation; private long gameDuration; @OneToMany @JoinColumn(name = "game_id", referencedColumnName = "game_id") List<Participant> participants = new ArrayList<>(); //... } .
.
.
I tried and failed like below.
package gg.om.omgg.domain.summoner; import com.querydsl.core.Tuple; import com.querydsl.jpa.impl.JPAQueryFactory; import com.querydsl.jpa.sql.JPASQLQuery; import com.querydsl.sql.SQLExpressions; import gg.om.omgg.domain.match.QMatch; import gg.om.omgg.domain.participant.QParticipant; import gg.om.omgg.web.dto.SummonerIntegrationInformationResponseDTO; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class SummonerCustomRepositoryImpl implements SummonerCustomRepository { private final JPASQLQuery jpasqlQuery; @Override public void mySolution() { QSummoner summoner = QSummoner.summoner; QMatch match = QMatch.match; // Error (I'm sorry that the indentation isn't pretty) jpasqlQuery .select(summoner, match, SQLExpressions.rowNumber().over()) .from(summoner) .leftJoin(summoner_match) .on(summoner.accountId.eq(summoner_match.accountId)) .leftJoin(match) .on(summoner_match.gameId.eq(match.gameId)) .fetch(); } } If there is a part that is difficult to understand, I will ask you a question.
https://stackoverflow.com/questions/67217677/how-to-join-jointable-using-querydsl April 23, 2021 at 12:55AM
没有评论:
发表评论