Skip to content

Instantly share code, notes, and snippets.

@thjanssen
Last active November 3, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thjanssen/d835a371e938883a56b1 to your computer and use it in GitHub Desktop.
Save thjanssen/d835a371e938883a56b1 to your computer and use it in GitHub Desktop.
CriteriaBuilder cb = this.em.getCriteriaBuilder();
// create update
CriteriaUpdate<Order> update = cb.createCriteriaUpdate(Order.class);
// set the root class
Root e = update.from(Order.class);
// set update and where clause
update.set("amount", newAmount);
update.where(cb.greaterThanOrEqualTo(e.get("amount"), oldAmount));
// perform update
this.em.createQuery(update).executeUpdate();
EntityGraph graph = this.em.createEntityGraph(Author.class);
Subgraph<Book> bookSubGraph = graph.addSubgraph(Author_.books);
SELECT DISTINCT a FROM Author a JOIN FETCH a.books b
@ManyToMany( mappedBy="authors", fetch=FetchType.LAZY)
@NamedEntityGraph(name = "graph.AuthorBooksReviews", 
attributeNodes = @NamedAttributeNode(value = "books"))
@NamedStoredProcedureQuery(
name = "getBooks",
procedureName = "get_books",
resultClasses = Book.class,
parameters = { @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, type = void.class) }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment