Last active
July 5, 2016 10:41
-
-
Save shelajev/d1446aad71ad688d4bbca299a6eaba7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity | |
| @NamedEntityGraph(name = "graph.AuthorBooks", attributeNodes = @NamedAttributeNode("books")) | |
| public class Author implements Serializable { | |
| … | |
| EntityGraph graph = entityManager.getEntityGraph("graph.AuthorBooks"); | |
| List<Author> authorsWithBooks = entityManager | |
| .createQuery("SELECT DISTINCT a FROM Author a", Author.class) | |
| .setHint("javax.persistence.loadgraph", graph) | |
| .getResultList(); | |
| List<Author> authors = entityManager.createQuery("SELECT a FROM Author a LEFT JOIN FETCH a.books").getResultList(); | |
| CriteriaBuilder cb = entityManager.getCriteriaBuilder(); | |
| CriteriaUpdate<Author> update = cb.createCriteriaUpdate(Author.class); | |
| update.from(Author.class); | |
| // specify the update statement | |
| update.set(Author_.firstName, "change me"); | |
| // specify the criteria for the update -- Author id >= 3 | |
| update.where(cb.greaterThanOrEqualTo(a.get(Author_.id), 3L)); | |
| entityManager.createQuery(update).executeUpdate(); | |
| Query::setFirstResult(); | |
| Query::setMaxResults(); | |
| entityManager.createQuery("SELECT a.id FROM Author a"); | |
| entityManager.createQuery("SELECT a FROM Author a"); | |
| @NamedStoredProcedureQuery( | |
| name = "procedureNameInJava", | |
| procedureName = "PROCEDURE_NAME_IN_DATABASE", | |
| parameters = { | |
| @StoredProcedureParameter(mode = ParameterMode.IN, type = Double.class, name = "a"), | |
| @StoredProcedureParameter(mode = ParameterMode.OUT, type = Double.class, name = "c") | |
| } | |
| ) | |
| StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery("procedureNameInJava"); | |
| query.setParameter("a", 1.0); | |
| query.execute(); | |
| Double c = (Double) query.getOutputParameterValue("c"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment