Hibernate aliases

My colleague Raj was recently updating a Hibernate criteria query which made use of aliases. He wanted to add a criterion that a value in a linked table must be null, so the most obvious change to make was to add another alias and the appropriate condition. e.g.
However, this query produced no results. Why? The answer lies in how an alias works. Creating an alias actually performs an inner join. However, on this occasion, the “sku” column is the foreign key that is used for the join. Hence, the join produces no results. To achieve the desired query, you can use the overloaded version of the addAlias method, that allows to chose the join type: createCriteria(String associationPath, int joinType) Alternatively, you can remove the alias and simply tweak the syntax of the restriction.
This entry was posted in Hibernate and tagged . Bookmark the permalink.

1 Response to Hibernate aliases

Leave a Reply

Your email address will not be published. Required fields are marked *

HTML tags are not allowed.

516,186 Spambots Blocked by Simple Comments