diff --git a/src/docbkx/jpa.xml b/src/docbkx/jpa.xml index 2dc8695fc..770c88aa7 100644 --- a/src/docbkx/jpa.xml +++ b/src/docbkx/jpa.xml @@ -886,6 +886,135 @@ int setFixedFirstnameFor(String firstname, String lastname); number of pages. + +
+ Configuring Fetch- and LoadGraphs + + The JPA 2.1 specification introduced support for specifiying + Fetch- and LoadGraphs that we also support via the + EntityGraph annotation which allows to + reference a NamedEntityGraph definition, + that can be annotated on an entity, to be used to configure the fetch + plan of the resulting query. The type (Fetch / Load) of the fetching can + be configured via the type attribute on the + EntityGraph annotation. Please have a + look at the JPA 2.1 Spec 3.7.4 for further reference. + + + Defining a named entity graph on an entity. + + @Entity +@NamedEntityGraph(name = "GroupInfo.detail", + attributeNodes = @NamedAttributeNode("members")) +public class GroupInfo { + + // default fetch mode is lazy. + @ManyToMany + List<GroupMember> members = new ArrayList<GroupMember>(); + + … +} + + + + Referencing a named entity graph definition on an repository + query method. + + @Repository +public interface GroupRepository extends CrudRepository<GroupInfo, String> { + + @EntityGraph(value = "GroupInfo.detail", type = EntityGraphType.LOAD) + GroupInfo getByGroupName(String name); + +} + + + +
+ + +
+ Stored procedures + + The JPA 2.1 specification introduced support for calling stored + procedures via the JPA criteria query API. We Introduced the + Procedure annotation for declaring stored + procedure metadata on a repository method. + + + The definition of the pus1inout procedure in HSQL DB. + + /; +DROP procedure IF EXISTS plus1inout +/; +CREATE procedure plus1inout (IN arg int, OUT res int) +BEGIN ATOMIC + set res = arg + 1; +END +/; + + +
+ Metadata for stored procedures can be configured via the + NamedStoredProcedureQuery annotation on + an entity type. + + + StoredProcedure metadata definitions on an entity. + + @Entity +@NamedStoredProcedureQuery(name = "User.plus1", procedureName = "plus1inout", parameters = { + @StoredProcedureParameter(mode = ParameterMode.IN, name = "arg", type = Integer.class), + @StoredProcedureParameter(mode = ParameterMode.OUT, name = "res", type = Integer.class) }) +public class User { + +} + +
+ +
+ Stored procedures can be referenced from a + Repository method in multiple ways. The + stored procedure to be called can either be defined directly via the + value or procedureName attribute of the + @Procedure annotation or indirectly via + the name attribute. If no name is configured the name of + the repository method is used as a fallback. + + + Referencing explicitly mapped procedure with name "plus1inout" + in database. + + @Procedure("plus1inout") +Integer explicitlyNamedPlus1inout(Integer arg); + + + + Referencing implicitly mapped procedure with name "plus1inout" + in database via <code>procedureName</code> alias. + + @Procedure(procedureName = "plus1inout") +Integer plus1inout(Integer arg); + + + + Referencing explicitly mapped named stored procedure + "User.plus1IO" in + <interfacename>EntityManager</interfacename>. + + @Procedure(name = "User.plus1IO") +Integer entityAnnotatedCustomNamedProcedurePlus1IO(@Param("arg") Integer arg); + + + + Referencing implicitly mapped named stored procedure + "User.plus1" in <interfacename>EntityManager</interfacename> via + method-name. + + @Procedure +Integer plus1(@Param("arg") Integer arg); + +