0
Hello, I’m trying to make an ordination in Criteria for the following query
:
SELECT *
FROM Social social
LEFT JOIN socialfavorite favorite ON (social.id = favorite.favoritedSocial_id AND favorite.user_id = 2)
ORDER BY favorite.id desc;
I transformed the sort part using the Criteria API:
Join<SocialUser, SocialFavorite> favorite = socialUser.join("socialFavorites");
favorite.on(builder.and(
builder.equal(socialUser.get("id"), favorite.get("favoritedSocial").get("id")),
builder.equal(favorite.get("user").get("alias"), search.getCurrentUserAlias())
));
if (orderParam.getType().equals(OrderType.ASC)) {
return builder.asc(favorite.get("id"));
}
return builder.desc(favorite.get("id"));
However, whenever Boer executes the orderBy
the following error occurs:
Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'socialuser2_.alias' in 'on clause'
socialuser2_.alias
is being informed where in thequery
?– Jakson Fischer
It is mounted by Criteria, probably when I do Join, but I found it very strange that he "gets lost" in this
– João
Yes, which is why I wondered, I took a look at the Criteria documentation last night, even in the examples I found on the net, I didn’t find anything like your... I’m trying to find a solution here, if I can I put it to you
– Jakson Fischer
Man, thank you so much. I’ve been trying several solutions for days, I even tried with subquery but gave the same error
– João