玩 Ebean .orderBy() 坏了?用“$”替换字符
Play Ebean .orderBy() broken? Replacing character with "$ "
找到以下Ebean
String join = "trackToArtists.artist.artistToTags.tag.stationToTags.station";
return find
.where()
.eq(join, station)
.ge(join + ".energyMin", settings.energyMin)
.le(join + ".energyMax", settings.energyMax)
.ge(join + ".livenessMin", settings.livenessMin)
.le(join + ".livenessMax", settings.livenessMax)
.ge(join + ".tempoMin", settings.tempoMin)
.le(join + ".tempoMax", settings.tempoMax)
.ge(join + ".acousticnessMin", settings.acousticnessMin)
.le(join + ".acousticnessMax", settings.acousticnessMax)
.ge(join + ".danceMin", settings.danceMin)
.le(join + ".danceMax", settings.danceMax)
.orderBy("trackToArtists.artist.artistToTags.score DESC")
.setMaxRows(Util.TopN)
.findList();
似乎生成了不正确的 SQL 查询,特别是 ORDER_BY:
Syntax error in SQL statement "SELECT DISTINCT T0.ID ... AND U6.DANCE_MAX <= ? ORDER BY $ RACKTOARTISTS[*].ARTIST.ARTISTTOTAGS SCORE DESC
完整 SQL(由 Ebean 生成):
SELECT DISTINCT T0.ID C0, T0.ACTIVE C1, T0.NAME C2, T0.MD5 C3, T0.EN_TRACK_ID C4, T0.EN_SONG_ID C5, T0.LASTR C6, T0.LAST_LISTENER_COUNT C7, T0.LAST_PLAY_COUNT C8, T0.LAST_PLAY_COUNT_NORM C9, T0.MB_ID C10, T0.EN_ANALYZER_VERSION C11, T0.DURATION C12, T0.EN_DANCEABILITY C13, T0.ENNERGY C14, T0.EN_KEY C15, T0.EN_KEY_CONFIDENCE C16, T0.LOUDNESS C17, T0.LOUDNESS_NORM C18, T0.EN_MODE C19, T0.EN_MODE_CONFIDENCE C20, T0.EN_TEMPO C21, T0.EN_TEMPO_CONFIDENCE C22, T0.EN_TEMPO_NORM C23, T0.EN_TIME_SIGNATURE C24, T0.EN_TIME_SIGNATURE_CONFIDENCE C25, T0.EN_SONG_HOTNESS C26, T0.EN_SPEECHINESS C27, T0.EN_ACOUSTICNESS C28, T0.EN_LIVENESS C29, T0.ENVALENCE C30, T0.LAST_ID C31, T0.LAST_URL C32 FROM TRACK T0 JOIN TRACK_TO_ARTIST U1 ON U1.TRACK_ID = T0.ID JOIN ARTIST U2 ON U2.ID = U1.ARTIST_ID JOIN ARTIST_TO_TAG U3 ON U3.ARTIST_ID = U2.ID JOIN TAG U4 ON U4.ID = U3.TAG_ID JOIN STATION_TO_TAG U5 ON U5.TAG_ID = U4.ID JOIN STATION U6 ON U6.ID = U5.STATION_ID WHERE U5.STATION_ID = ? AND U6.ENERGY_MIN >= ? AND U6.ENERGY_MAX <= ? AND U6.LIVENESS_MIN >= ? AND U6.LIVENESS_MAX <= ? AND U6.TEMPO_MIN >= ? AND U6.TEMPO_MAX <= ? AND U6.ACOUSTICNESS_MIN >= ? AND U6.ACOUSTICNESS_MAX <= ? AND U6.DANCE_MIN >= ? AND U6.DANCE_MAX <= ? ORDER BY $ RACKTOARTISTS[*].ARTIST.ARTISTTOTAGS SCORE DESC LIMIT 11
我什至不知道是什么导致它将 "trackToArtists" 解释为“$ RACKTOARTISTS”。
尝试做:
find.fetch("trackToArtists.artist.artistToTags")
.where()
.eq(join, station)
.ge(join + ".energyMin", settings.energyMin)
.le(join + ".energyMax", settings.energyMax)
.ge(join + ".livenessMin", settings.livenessMin)
.le(join + ".livenessMax", settings.livenessMax)
.ge(join + ".tempoMin", settings.tempoMin)
.le(join + ".tempoMax", settings.tempoMax)
.ge(join + ".acousticnessMin", settings.acousticnessMin)
.le(join + ".acousticnessMax", settings.acousticnessMax)
.ge(join + ".danceMin", settings.danceMin)
.le(join + ".danceMax", settings.danceMax)
.orderBy("trackToArtists.artist.artistToTags.score DESC")
.setMaxRows(Util.TopN)
.findList();
找到以下Ebean
String join = "trackToArtists.artist.artistToTags.tag.stationToTags.station";
return find
.where()
.eq(join, station)
.ge(join + ".energyMin", settings.energyMin)
.le(join + ".energyMax", settings.energyMax)
.ge(join + ".livenessMin", settings.livenessMin)
.le(join + ".livenessMax", settings.livenessMax)
.ge(join + ".tempoMin", settings.tempoMin)
.le(join + ".tempoMax", settings.tempoMax)
.ge(join + ".acousticnessMin", settings.acousticnessMin)
.le(join + ".acousticnessMax", settings.acousticnessMax)
.ge(join + ".danceMin", settings.danceMin)
.le(join + ".danceMax", settings.danceMax)
.orderBy("trackToArtists.artist.artistToTags.score DESC")
.setMaxRows(Util.TopN)
.findList();
似乎生成了不正确的 SQL 查询,特别是 ORDER_BY:
Syntax error in SQL statement "SELECT DISTINCT T0.ID ... AND U6.DANCE_MAX <= ? ORDER BY $ RACKTOARTISTS[*].ARTIST.ARTISTTOTAGS SCORE DESC
完整 SQL(由 Ebean 生成):
SELECT DISTINCT T0.ID C0, T0.ACTIVE C1, T0.NAME C2, T0.MD5 C3, T0.EN_TRACK_ID C4, T0.EN_SONG_ID C5, T0.LASTR C6, T0.LAST_LISTENER_COUNT C7, T0.LAST_PLAY_COUNT C8, T0.LAST_PLAY_COUNT_NORM C9, T0.MB_ID C10, T0.EN_ANALYZER_VERSION C11, T0.DURATION C12, T0.EN_DANCEABILITY C13, T0.ENNERGY C14, T0.EN_KEY C15, T0.EN_KEY_CONFIDENCE C16, T0.LOUDNESS C17, T0.LOUDNESS_NORM C18, T0.EN_MODE C19, T0.EN_MODE_CONFIDENCE C20, T0.EN_TEMPO C21, T0.EN_TEMPO_CONFIDENCE C22, T0.EN_TEMPO_NORM C23, T0.EN_TIME_SIGNATURE C24, T0.EN_TIME_SIGNATURE_CONFIDENCE C25, T0.EN_SONG_HOTNESS C26, T0.EN_SPEECHINESS C27, T0.EN_ACOUSTICNESS C28, T0.EN_LIVENESS C29, T0.ENVALENCE C30, T0.LAST_ID C31, T0.LAST_URL C32 FROM TRACK T0 JOIN TRACK_TO_ARTIST U1 ON U1.TRACK_ID = T0.ID JOIN ARTIST U2 ON U2.ID = U1.ARTIST_ID JOIN ARTIST_TO_TAG U3 ON U3.ARTIST_ID = U2.ID JOIN TAG U4 ON U4.ID = U3.TAG_ID JOIN STATION_TO_TAG U5 ON U5.TAG_ID = U4.ID JOIN STATION U6 ON U6.ID = U5.STATION_ID WHERE U5.STATION_ID = ? AND U6.ENERGY_MIN >= ? AND U6.ENERGY_MAX <= ? AND U6.LIVENESS_MIN >= ? AND U6.LIVENESS_MAX <= ? AND U6.TEMPO_MIN >= ? AND U6.TEMPO_MAX <= ? AND U6.ACOUSTICNESS_MIN >= ? AND U6.ACOUSTICNESS_MAX <= ? AND U6.DANCE_MIN >= ? AND U6.DANCE_MAX <= ? ORDER BY $ RACKTOARTISTS[*].ARTIST.ARTISTTOTAGS SCORE DESC LIMIT 11
我什至不知道是什么导致它将 "trackToArtists" 解释为“$ RACKTOARTISTS”。
尝试做:
find.fetch("trackToArtists.artist.artistToTags")
.where()
.eq(join, station)
.ge(join + ".energyMin", settings.energyMin)
.le(join + ".energyMax", settings.energyMax)
.ge(join + ".livenessMin", settings.livenessMin)
.le(join + ".livenessMax", settings.livenessMax)
.ge(join + ".tempoMin", settings.tempoMin)
.le(join + ".tempoMax", settings.tempoMax)
.ge(join + ".acousticnessMin", settings.acousticnessMin)
.le(join + ".acousticnessMax", settings.acousticnessMax)
.ge(join + ".danceMin", settings.danceMin)
.le(join + ".danceMax", settings.danceMax)
.orderBy("trackToArtists.artist.artistToTags.score DESC")
.setMaxRows(Util.TopN)
.findList();