I learn JPA and tried the following code:
CriteriaBuilder queryBuilder = em.getCriteriaBuilder();
CriteriaQuery<PersonDI> criteriaQuery = queryBuilder.createQuery(PersonDI.class);
Root<PersonDI> personDI = criteriaQuery.from(PersonDI.class);
Fetch<PersonDI, ContactDI> contactDI = personDI.fetch("contacts", JoinType.LEFT);
criteriaQuery.where(queryBuilder.equal(personDI.get("guid"), guids.get(0)));
criteriaQuery.select(personDI).distinct(true);
TypedQuery<PersonDI> query = em.createQuery(criteriaQuery);
So one person has many contacts. The code is working. I use H2 database and EclipseLink. However, I can't understand what {oj...}
means in SQL. Explain please.
This is the generated SQL:
SELECT DISTINCT t1.col0, t1.col3, t1.col1, t1.col2, t0.col0, t0.col2 FROM {oj tbl0 t1 LEFT OUTER JOIN tbl1 t0 ON (t0.col1 = t1.col0)} WHERE (t1.col0 = ?)