EclipseLink在使用Criteria API时不生成连接

时间:2016-11-29 21:56:18

标签: sql jpa eclipselink criteria-api

我正在使用EclipseLink来构建查询。但是我担心它在使用Criteria API定义的任何查询中都没有使用JOIN语法。

请参阅以下查询:

// create criteria builder and create query
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Org> query = cb.createQuery(Org.class);

// define root and joined tables
Root<Relationship> rel = query.from(Relationship.class);
Join<Relationship, Org> theOrg = rel.join(Relationship_.party1);

// finish query
query.where(cb.equal(rel.get(Relationship_.party0Id), filterValue));
query.select(theOrg);
query.orderBy(cb.asc(theOrg.get(Org_.name)));

// return results
...

我期待的是:

SELECT O.FIELD1, O.FIELD2, ... O.FIELDN
FROM RELATIONSHIP R
INNER JOIN ORG O ON R.PARTY1 = O.ID
WHERE R.PARTY0 = <filterValue>
ORDER BY O.NAME ASC

但是我得到了这个:

SELECT t0.ID, ... t0.FIELDN
FROM ORG t0, RELATIONSHIP t1 
WHERE ((t1.PARTY0 = ?) AND (t0.ID = t1.PARTY1)) 
ORDER BY t0.NAME ASC

有什么遗漏?或者它只是它的工作方式?

我正在使用Oracle后端

谢谢!

0 个答案:

没有答案