Play Ebean .orderBy() broken? Replacing character with "$ "

143 views Asked by At

The following Ebean find

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();

seems to be generating the incorrect SQL query, specifically the ORDER_BY:

Syntax error in SQL statement "SELECT DISTINCT T0.ID ... AND U6.DANCE_MAX <= ?  ORDER BY $  RACKTOARTISTS[*].ARTIST.ARTISTTOTAGS SCORE DESC 

Full SQL (generated by 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

I don't even have the slightest idea what could be causing it to interpret "trackToArtists" as "$ RACKTOARTISTS".

1

There are 1 answers

0
cperez On BEST ANSWER

Try doing:

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();