OBGM-545 Fix pagination for product list#4135
OBGM-545 Fix pagination for product list#4135awalkowiak merged 1 commit intofeature/upgrade-to-grails-3.3.10from
Conversation
jmiranda
left a comment
There was a problem hiding this comment.
A workaround for that was to add an additional criteria to the createAlias, which was to join by product.id and synonym.product_id AND synonymTypeCode = SynonymTypeCode.DISPLAY_NAME - this will remove the duplicates, because we can have only one DISPLAY_NAME synonym.
@kchelstowski What if this last part wasn't true? Is there a way for us to write this query so we don't get duplicates.
In the original query, I know there would be a record returned for products without a display name. But does including the "like" restriction filter these results out?
Also why do we use "like" instead of "equals".
|
@jmiranda obviously if the last part wasn't true, we might have a problem again, but I'd say the risk is very low. As for |
The problem was with a difference between joining type in Grails 1 vs Grails 3 - we were fixing this once, but the join was added in a wrong place, because we should join synonyms only if we provide
params.name.Additionally - the pagination was showing wrong results, because the
LEFT_JOINwas giving us duplicate results which was then cut by the distinct.Why it was giving duplicate results is due to
LEFT_JOINbeing used - if a product has 4 synonyms, it was considered 4 times in the query.A workaround for that was to add an additional criteria to the
createAlias, which was to join byproduct.idandsynonym.product_idANDsynonymTypeCode = SynonymTypeCode.DISPLAY_NAME- this will remove the duplicates, because we can have only oneDISPLAY_NAMEsynonym.Fortunately we can add additional criteria in
createAlias- since it might be difficult to find, I'm attaching a link to docs of that: https://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/Criteria.html#createAlias(java.lang.String,%20java.lang.String,%20org.hibernate.sql.JoinType,%20org.hibernate.criterion.Criterion)