(Lazy) LEFT OUTER JOIN using the Hibernate Criteria API

Markos Fragkakis picture Markos Fragkakis · Feb 5, 2010 · Viewed 40.7k times · Source

I want to perform a LEFT OUTER JOIN between two tables using the Criteria API. All I could find in the Hibernate documentation is this method:

Criteria criteria = this.crudService
            .initializeCriteria(Applicant.class)
            .setFetchMode("products", FetchMode.JOIN)
            .createAlias("products", "product");

However, this either performs an inner join or a right outer join, because of the number of results it returns.

I also want my join to be Lazy. How can I do this?

Cheers!

UPDATE: It seems that using aliases makes the join INNER JOIN automatically. There is something in the "background story" I have not grasped yet. So, no alias today. This leaves me with the problem of applying restrictions to the two tables, because they both have a column (or property, if this is more appropriate) 'name'.

Answer

sdavids picture sdavids · Feb 6, 2010

If you need to left join on the products table just do:

.....createAlias("products", "product", Criteria.LEFT_JOIN);