Skip to content

Instantly share code, notes, and snippets.

@elyas-bhy
Last active January 3, 2016 22:59
Show Gist options
  • Save elyas-bhy/8532332 to your computer and use it in GitHub Desktop.
Save elyas-bhy/8532332 to your computer and use it in GitHub Desktop.
A workaround of Google App Engine's limitations regarding Criteria joins
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Foo> q = cb.createQuery(Foo.class);
Root<Foo> foo = q.from(Foo.class);
foo.join("bar").alias("b1");
foo.alias("b1");
q.select(foo).where(cb.equal(foo.get("id"), "42"));
foo.alias("f1");
TypedQuery<Foo> query = em.createQuery(q);
List<Foo> foos = query.getResultList();
@elyas-bhy
Copy link
Author

The resulting statement is equivalent to:

SELECT f FROM Foo f JOIN f.bar b WHERE b.id = "42"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment