Search code examples
javahibernatecriteria

Hibernate Critieria join two tables with condition on 2nd table and result the 1st table


I have a question using Hibernate Criteria, I need to convert this query using criteria.

SELECT * FROM A a_ INNER JOIN B b_ ON a_.column1=b_.column1 AND b_.column2 IN (X,Y) AND active='Y';

I need the result as table A.


Solution

  • If the associations are defined, see http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycriteria.html#querycriteria-associations

    In case associations are not specified in the entities definition, you can't use criteria. You can use HQL to do inner joins (need to write in implicit join notation), for doing left joins you have to use native SQL.