I'm new to JPA and I want to create this query using the API criteria:
SELECT company.*
FROM company
LEFT OUTER JOIN address ON company.id = address.company_id AND address.postal_code = '54000'
ORDER BY company.id;
After searching and reflexion, I tried this code, which seems logical to me:
...
CriteriaQuery<Company> query = criteriaBuilder.createQuery(Company.class)
Root<Company> defCompany = query.from(Company.class);
Join joinAddresses = defCompany.join("addresses", JoinType.LEFT);
joinAddresses.on(criteriaBuilder.equal(joinAddresses.get("postalCode"), "54000"));
query.orderBy(criteriaBuilder.asc(defCompany.get("id")));
List<Company> companies = entityManager.createQuer(query)
.getResultList();
...
But OpenJPA throws this error:
ERROR OpenEJB- EjbTransactionUtil.handleSystemException: org.apache.openjpa.persistence.criteria.Joins$List.on(Ljavax/persistence/criteria/Expression;)Ljavax/persistence/criteria/Join;
java.lang.AbstractMethodError: org.apache.openjpa.persistence.criteria.Joins$List.on(Ljavax/persistence/criteria/Expression;)Ljavax/persistence/criteria/Join;
I hope someone tried to do this before, I think probably but I can't find a thread or question about this.
JOIN ON
is part of JPA 2.1, and OpenJPA does not implement JPA 2.1.Use a JPA provider that implements JPA 2.1 (e.g DataNucleus JPA, EclipseLink, Hibernate), or don't use ON clauses with JOINs (or put the ON in the WHERE clause ... not quite equivalent clearly)