{"id":33317,"date":"2014-11-26T22:00:24","date_gmt":"2014-11-26T20:00:24","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=33317"},"modified":"2014-11-26T08:35:44","modified_gmt":"2014-11-26T06:35:44","slug":"jpa-entity-graphs","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html","title":{"rendered":"JPA Entity Graphs"},"content":{"rendered":"<p>One of the latest features in <a href=\"http:\/\/download.oracle.com\/otndocs\/jcp\/persistence-2_1-fr-eval-spec\/index.html\">JPA 2.1<\/a> is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customise the data that is retrieved with a query or find operation. When working with mid to large size applications is common to display data from the same entity in different and many ways. In other cases, you just want to select a smallest set of information to optimize the performance of your application.<\/p>\n<p>You don\u2019t have many mechanisms to control what is loaded or not in a JPA Entity. You could use <b>EAGER<\/b> \/ <b>LAZY<\/b> fetching, but these definitions are pretty much static. You were unable to change their behaviour when retrieving data, meaning that you were stuck with what was defined in the entity. Changing these in mid development is a nightmare, since it can cause queries to behave unexpectedly. Another way to control loading is to write specific JPQL queries. You usually end up with very similar queries and the following methods: <code>findEntityWithX<\/code>,  <code>findEntityWithY<\/code>, <code>findEntityWithXandY<\/code>, and so on.<\/p>\n<p>Before <a href=\"http:\/\/download.oracle.com\/otndocs\/jcp\/persistence-2_1-fr-eval-spec\/index.html\">JPA 2.1<\/a>, the implementations already supported a non standard way to load data similar to Entity Graphs. You have <a href=\"https:\/\/docs.jboss.org\/hibernate\/orm\/3.5\/reference\/en\/html\/performance.html#performance-fetching-profiles\">Hibernate Fetch Profiles<\/a>, <a href=\"http:\/\/openjpa.apache.org\/builds\/1.0.3\/apache-openjpa-1.0.3\/docs\/manual\/ref_guide_fetch.html\">OpenJPA Fetch Groups<\/a> and <a href=\"http:\/\/eclipse.org\/eclipselink\/documentation\/2.5\/jpa\/extensions\/a_fetchgroup.htm\">EclipseLink Fetch Groups<\/a>. It was logical to have this kind of behaviour in the specification. It allows you a much finer and detail control on what you need to load using a standard API.<\/p>\n<h2>Example<\/h2>\n<p>Consider the following Entity Graph:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/11\/movie-entity-graph.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-33621\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/11\/movie-entity-graph.png\" alt=\"movie-entity-graph\" width=\"473\" height=\"373\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/11\/movie-entity-graph.png 1036w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/11\/movie-entity-graph-300x236.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/11\/movie-entity-graph-1024x808.png 1024w\" sizes=\"(max-width: 473px) 100vw, 473px\" \/><\/a><\/p>\n<p>(Probably the relationships should be N to N, but lets keep it simple).<\/p>\n<p>And the Movie Entity has the following definition:<\/p>\n<p><em>Movie.java<\/em><\/p>\n<pre class=\"brush:java\">@Entity\r\n@Table(name = \"MOVIE_ENTITY_GRAPH\")\r\n@NamedQueries({\r\n    @NamedQuery(name = \"Movie.findAll\", query = \"SELECT m FROM Movie m\")\r\n})\r\n@NamedEntityGraphs({\r\n    @NamedEntityGraph(\r\n        name = \"movieWithActors\",\r\n        attributeNodes = {\r\n            @NamedAttributeNode(\"movieActors\")\r\n        }\r\n    ),\r\n    @NamedEntityGraph(\r\n        name = \"movieWithActorsAndAwards\",\r\n        attributeNodes = {\r\n            @NamedAttributeNode(value = \"movieActors\", subgraph = \"movieActorsGraph\")\r\n        },\r\n        subgraphs = {\r\n            @NamedSubgraph(\r\n                    name = \"movieActorsGraph\",\r\n                    attributeNodes = {\r\n                        @NamedAttributeNode(\"movieActorAwards\")\r\n                    }\r\n            )\r\n        }\r\n    )\r\n})\r\npublic class Movie implements Serializable {\r\n    @Id\r\n    private Integer id;\r\n\r\n    @NotNull\r\n    @Size(max = 50)\r\n    private String name;\r\n\r\n    @OneToMany\r\n    @JoinColumn(name = \"ID\")\r\n    private Set&lt;MovieActor&gt; movieActors;\r\n\r\n    @OneToMany(fetch = FetchType.EAGER)\r\n    @JoinColumn(name = \"ID\")\r\n    private Set&lt;MovieDirector&gt; movieDirectors;\r\n\r\n    @OneToMany\r\n    @JoinColumn(name = \"ID\")\r\n    private Set&lt;MovieAward&gt; movieAwards;\r\n}<\/pre>\n<p>Looking closer to the entity, we can see that we have three 1 to N relationships and <code>movieDirectors<\/code> is set to be Eagerly loaded. The other relationships are set to the default Lazy loading strategy. If we want to change this behaviour, we can define different loading models by using the annotation <code>@NamedEntityGraph<\/code>. Just set a name to identify it and then use the <code>@NamedAttributeNode<\/code> to specify which attributes of the root entity that you want to load. For relationships you need to set a name to the subgraph and then use <code>@NamedSubgraph<\/code>. In detail:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3>Annotations<\/h3>\n<p><em>Entity Graph movieWithActors<\/em><\/p>\n<pre class=\"brush:java\">    @NamedEntityGraph(\r\n        name = \"movieWithActors\",\r\n        attributeNodes = {\r\n            @NamedAttributeNode(\"movieActors\")\r\n        }\r\n    ) )<\/pre>\n<p>This defines an Entity Graph with name <code>movieWithActors<\/code> and specifies that the relationship <code>movieActors<\/code> should be loaded.<\/p>\n<p><em>Entity Graph movieWithActorsAndAwards<\/em><\/p>\n<pre class=\"brush:java\">    @NamedEntityGraph(\r\n        name = \"movieWithActorsAndAwards\",\r\n        attributeNodes = {\r\n            @NamedAttributeNode(value = \"movieActors\", subgraph = \"movieActorsGraph\")\r\n        },\r\n        subgraphs = {\r\n            @NamedSubgraph(\r\n                    name = \"movieActorsGraph\",\r\n                    attributeNodes = {\r\n                        @NamedAttributeNode(\"movieActorAwards\")\r\n                    }\r\n            )\r\n        }\r\n    )<\/pre>\n<p>This defines an Entity Graph with name <code>movieWithActorsAndAwards<\/code> and specifies that the relationship <code>movieActors<\/code> should be loaded. Additionally, it also specifies that the relationship <code>movieActors<\/code> should load the <code>movieActorAwards<\/code>.<\/p>\n<p>Note that we don\u2019t specify the <code>id<\/code> attribute in the Entity Graph. This is because primary keys are always fetched regardless of what\u2019s being specified. This is also true for version attributes.<\/p>\n<h3>Hints<\/h3>\n<p>To use the Entity Graphs defined in a query, you need to set them as an hint. You can use two hint properties and these also influences the way the data is loaded.<\/p>\n<p>You can use <code>javax.persistence.fetchgraph<\/code> and this hint will treat all the specified attributes in the Entity Graph as <code>FetchType.EAGER<\/code>. Attributes that are not specified are treated as <code>FetchType.LAZY<\/code>.<\/p>\n<p>The other property hint is <code>javax.persistence.loadgraph<\/code>. This will treat all the specified attributes in the Entity Graph as <code>FetchType.EAGER<\/code>. Attributes that are not specified are treated to their specified or default <code>FetchType<\/code>.<\/p>\n<p>To simplify, and based on our example when applying the Entity Graph <code>movieWithActors<\/code>:<\/p>\n<table border=\"1\" style=\"width:800px\">\n<tbody align=\"center\">\n<tr>\n<th><\/th>\n<th>Default \/ Specified<\/th>\n<th>javax.persistence.fetchgraph<\/th>\n<th>javax.persistence.loadgraph<\/th>\n<\/tr>\n<tr>\n<td><b>movieActors<\/b><\/td>\n<td>LAZY<\/td>\n<td>EAGER<\/td>\n<td>EAGER<\/td>\n<\/tr>\n<tr>\n<td><b>movieDirectors<\/b><\/td>\n<td>EAGER<\/td>\n<td>LAZY<\/td>\n<td>EAGER<\/td>\n<\/tr>\n<tr>\n<td><b>movieAwards<\/b><\/td>\n<td>LAZY<\/td>\n<td>LAZY<\/td>\n<td>LAZY<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In theory, this should be how the different relationships are fetched. In practice, it may not work this way, because the <a href=\"http:\/\/download.oracle.com\/otndocs\/jcp\/persistence-2_1-fr-eval-spec\/index.html\">JPA 2.1<\/a> specification also states that the JPA provider can always fetch extra state beyond the one specified in the Entity Graph. This is because the provider can optimize which data to fetch and end up loading much more stuff. You need to check your provider behaviour. For instance Hibernate always fetch everything that is specified as EAGER even when using the <code>javax.persistence.fetchgraph<\/code> hint. Check the issue <a href=\"https:\/\/hibernate.atlassian.net\/browse\/HHH-8776\">here<\/a>.<\/p>\n<h3>Query<\/h3>\n<p>Performing the query is easy. You do it as you would normally do, but just call <code>setHint<\/code> on the <code>Query<\/code> object:<\/p>\n<p><em>Hint Entity Graph<\/em><\/p>\n<pre class=\"brush:java\">    @PersistenceContext\r\n    private EntityManager entityManager;\r\n\r\n    public List&lt;Movie&gt; listMovies(String hint, String graphName) {\r\n        return entityManager.createNamedQuery(\"Movie.findAll\")\r\n                            .setHint(hint, entityManager.getEntityGraph(graphName))\r\n                            .getResultList();\r\n    }<\/pre>\n<p>To get the Entity Graph you want to use on your query, you need to call the <code>getEntityGraph<\/code> method on the <code>EntityManager<\/code> and pass the name. Then use the reference in the hint. Hint must be either <code>javax.persistence.fetchgraph<\/code> or <code>javax.persistence.loadgraph<\/code>.<\/p>\n<h3>Programmatic<\/h3>\n<p>Annotations may become verbose, especially if you have big graphs or many Entity Graphs. Instead of using annotations, you can programmatically define Entity Graphs. Let\u2019s see how:<\/p>\n<p>Start by adding a static meta model Entity Class:<\/p>\n<p><em>Movie_.java<\/em><\/p>\n<pre class=\"brush:java\">@StaticMetamodel(Movie.class)\r\npublic abstract class Movie_ {\r\n    public static volatile SingularAttribute&lt;Movie, Integer&gt; id;\r\n    public static volatile SetAttribute&lt;Movie, MovieAward&gt; movieAwards;\r\n    public static volatile SingularAttribute&lt;Movie, String&gt; name;\r\n    public static volatile SetAttribute&lt;Movie, MovieActor&gt; movieActors;\r\n    public static volatile SetAttribute&lt;Movie, MovieDirector&gt; movieDirectors;\r\n}<\/pre>\n<p>This is not really needed, you can reference the attributes by their string names, but this will give you type safety.<\/p>\n<p><em>Programmatic Entity Graph<\/em><\/p>\n<pre class=\"brush:java\">    EntityGraph&lt;Movie&gt; fetchAll = entityManager.createEntityGraph(Movie.class);\r\n    fetchAll.addSubgraph(Movie_.movieActors);\r\n    fetchAll.addSubgraph(Movie_.movieDirectors);\r\n    fetchAll.addSubgraph(Movie_.movieAwards);<\/pre>\n<p>This Entity Graph specifies that all relationships of the Entity must be loaded. You can now adjust to your own use cases.<\/p>\n<h2>Resources<\/h2>\n<p>You can find this sample code in the <a href=\"https:\/\/github.com\/javaee-samples\/javaee7-samples\">Java EE samples<\/a> at Github. Check it <a href=\"https:\/\/github.com\/javaee-samples\/javaee7-samples\/tree\/master\/jpa\/entitygraph\">here<\/a>.<\/p>\n<p><b>Extra Note:<\/b> currently there is a bug in EclipseLink \/ Glassfish that prevents <code>javax.persistence.loadgraph<\/code> hint from working properly. Check the issue <a href=\"https:\/\/java.net\/jira\/browse\/GLASSFISH-21200\">here<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>Entity Graphs filled a gap missing in the JPA specification. They are an extra mechanism that helps you to query for what you really need. They also help you to improve the performance of your application. But be smart when using them. There might be a better way.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/www.radcortez.com\/jpa-entity-graphs\/\">JPA Entity Graphs<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\/\">JCG partner<\/a> Roberto Cortez at the <a href=\"http:\/\/www.radcortez.com\/\">Roberto Cortez Java Blog<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>One of the latest features in JPA 2.1 is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customise the data that is retrieved with a query or find operation. When working with mid to large size applications is common to display data from the same entity &hellip;<\/p>\n","protected":false},"author":592,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[33],"class_list":["post-33317","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jpa"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JPA Entity Graphs<\/title>\n<meta name=\"description\" content=\"One of the latest features in JPA 2.1 is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customise the data\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JPA Entity Graphs\" \/>\n<meta property=\"og:description\" content=\"One of the latest features in JPA 2.1 is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customise the data\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/radcortez\" \/>\n<meta property=\"article:published_time\" content=\"2014-11-26T20:00:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Roberto Cortez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/radcortez\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Roberto Cortez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html\"},\"author\":{\"name\":\"Roberto Cortez\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/d8791115988e922dbffae8d09223a72e\"},\"headline\":\"JPA Entity Graphs\",\"datePublished\":\"2014-11-26T20:00:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html\"},\"wordCount\":890,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"JPA\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html\",\"name\":\"JPA Entity Graphs\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2014-11-26T20:00:24+00:00\",\"description\":\"One of the latest features in JPA 2.1 is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customise the data\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/jpa-entity-graphs.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"JPA Entity Graphs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/d8791115988e922dbffae8d09223a72e\",\"name\":\"Roberto Cortez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b40fa2b3df6cfc7ad81ed1509ed2a17fe6a200e409fb0aa8d9e2ab72b64b684?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b40fa2b3df6cfc7ad81ed1509ed2a17fe6a200e409fb0aa8d9e2ab72b64b684?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b40fa2b3df6cfc7ad81ed1509ed2a17fe6a200e409fb0aa8d9e2ab72b64b684?s=96&d=mm&r=g\",\"caption\":\"Roberto Cortez\"},\"description\":\"My name is Roberto Cortez and I was born in Venezuela, but I have spent most of my life in Coimbra \u2013 Portugal, where I currently live. I am a professional Java Developer working in the software development industry, with more than 8 years of experience in business areas like Finance, Insurance and Government. I work with many Java based technologies like JavaEE, Spring, Hibernate, GWT, JBoss AS and Maven just to name a few, always relying on my favorite IDE: IntelliJ IDEA. Most recently, I became a Freelancer \\\/ Independent Contractor. My new position is making me travel around the world (an old dream) to customers, but also to attend Java conferences. The direct contact with the Java community made me want to become an active member in the community itself. For that reason, I have created the Coimbra Java User Group, started to contribute to Open Source on Github and launched my own blog (www.radcortez.com), so I can share some of the knowledge that I gained over the years.\",\"sameAs\":[\"http:\\\/\\\/www.radcortez.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/radcortez\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/radcortez\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/radcortez\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/roberto-cortez\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JPA Entity Graphs","description":"One of the latest features in JPA 2.1 is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customise the data","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html","og_locale":"en_US","og_type":"article","og_title":"JPA Entity Graphs","og_description":"One of the latest features in JPA 2.1 is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customise the data","og_url":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/radcortez","article_published_time":"2014-11-26T20:00:24+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Roberto Cortez","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/radcortez","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Roberto Cortez","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html"},"author":{"name":"Roberto Cortez","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/d8791115988e922dbffae8d09223a72e"},"headline":"JPA Entity Graphs","datePublished":"2014-11-26T20:00:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html"},"wordCount":890,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["JPA"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html","url":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html","name":"JPA Entity Graphs","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2014-11-26T20:00:24+00:00","description":"One of the latest features in JPA 2.1 is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customise the data","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/jpa-entity-graphs.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"JPA Entity Graphs"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/d8791115988e922dbffae8d09223a72e","name":"Roberto Cortez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3b40fa2b3df6cfc7ad81ed1509ed2a17fe6a200e409fb0aa8d9e2ab72b64b684?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3b40fa2b3df6cfc7ad81ed1509ed2a17fe6a200e409fb0aa8d9e2ab72b64b684?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3b40fa2b3df6cfc7ad81ed1509ed2a17fe6a200e409fb0aa8d9e2ab72b64b684?s=96&d=mm&r=g","caption":"Roberto Cortez"},"description":"My name is Roberto Cortez and I was born in Venezuela, but I have spent most of my life in Coimbra \u2013 Portugal, where I currently live. I am a professional Java Developer working in the software development industry, with more than 8 years of experience in business areas like Finance, Insurance and Government. I work with many Java based technologies like JavaEE, Spring, Hibernate, GWT, JBoss AS and Maven just to name a few, always relying on my favorite IDE: IntelliJ IDEA. Most recently, I became a Freelancer \/ Independent Contractor. My new position is making me travel around the world (an old dream) to customers, but also to attend Java conferences. The direct contact with the Java community made me want to become an active member in the community itself. For that reason, I have created the Coimbra Java User Group, started to contribute to Open Source on Github and launched my own blog (www.radcortez.com), so I can share some of the knowledge that I gained over the years.","sameAs":["http:\/\/www.radcortez.com\/","https:\/\/www.facebook.com\/radcortez","https:\/\/www.linkedin.com\/in\/radcortez","https:\/\/x.com\/https:\/\/twitter.com\/radcortez"],"url":"https:\/\/www.javacodegeeks.com\/author\/roberto-cortez"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/33317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/592"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=33317"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/33317\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=33317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=33317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=33317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}