{"id":31623,"date":"2014-10-15T07:00:35","date_gmt":"2014-10-15T04:00:35","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=31623"},"modified":"2015-08-28T11:15:55","modified_gmt":"2015-08-28T08:15:55","slug":"jpa-tutorial-mapping-entities-part-3","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html","title":{"rendered":"JPA Tutorial: Mapping Entities \u2013 Part 3"},"content":{"rendered":"<p>In my <a title=\"JPA Tutorial: Mapping Entities \u2013 Part 2\" href=\"http:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-2.html\">last article<\/a> I showed two different ways to read\/write\u00a0persistent entity state\u00a0\u2013 field and property. When field access mode\u00a0is used, JPA directly reads the state values from the fields of an entity using reflection. It directly translates the field names into database column names if we do not specify the column names explicitly. \u00a0In case of property access mode, the getter\/setter methods are used to read\/write the state\u00a0values. In this case we annotate the getter methods of the entity states instead of the fields using the same annotations. If we do not explicitly specify the\u00a0database\u00a0column names then they are determined following the JavaBean convention, that is by removing the \u201cget\u201d portion from the getter method name and converting the first letter of the rest of the method name\u00a0to lowercase character.<\/p>\n<p>&nbsp;<br \/>\nWe can specify which access mode to use for an entity by using the <em>@Access<\/em> annotation in\u00a0the entity class declaration. This annotation takes an argument of type <em>AccessType<\/em>\u00a0(defined in the <em>javax.persistence<\/em> package)\u00a0enum, which has two different values corresponding to two different access modes \u2013 <em>FIELD<\/em> and <em>PROPERTY<\/em>. As an example, we can specify\u00a0property access mode for the <em>Address<\/em> entity in the following way:<\/p>\n<pre class=\" brush:java\">@Entity\r\n@Table(name = \"tbl_address\")\r\n@Access(AccessType.PROPERTY)\r\npublic class Address {\r\n  private Integer id;\r\n  private String street;\r\n  private String city;\r\n  private String province;\r\n  private String country;\r\n  private String postcode;\r\n  private String transientColumn;\r\n\r\n  @Id\r\n  @GeneratedValue\r\n  @Column(name = \"address_id\")\r\n  public Integer getId() {\r\n    return id;\r\n  }\r\n\r\n  public Address setId(Integer id) {\r\n    this.id = id;\r\n    return this;\r\n  }\r\n\r\n  public String getStreet() {\r\n    return street;\r\n  }\r\n\r\n  public Address setStreet(String street) {\r\n    this.street = street;\r\n    return this;\r\n  }\r\n\r\n  public String getCity() {\r\n    return city;\r\n  }\r\n\r\n  public Address setCity(String city) {\r\n    this.city = city;\r\n    return this;\r\n  }\r\n\r\n  public String getProvince() {\r\n    return province;\r\n  }\r\n\r\n  public Address setProvince(String province) {\r\n    this.province = province;\r\n    return this;\r\n  }\r\n\r\n  public String getCountry() {\r\n    return country;\r\n  }\r\n\r\n  public Address setCountry(String country) {\r\n    this.country = country;\r\n    return this;\r\n  }\r\n\r\n  public String getPostcode() {\r\n    return postcode;\r\n  }\r\n\r\n  public Address setPostcode(String postcode) {\r\n    this.postcode = postcode;\r\n    return this;\r\n  }\r\n}<\/pre>\n<p>Couple of\u00a0points to note about the above example:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ol>\n<li>As discussed before, we are now annotating the getter method of the entity id with the\u00a0<em>@Id<\/em>,\u00a0<em>@GeneratedValue<\/em> and <em>@Column<\/em> annotations.<\/li>\n<li>Since now column names will be determined by parsing the getter methods, we do not need to mark the\u00a0<em>transientColumn<\/em> field with the <em>@Transient<\/em> annotation anymore. However if <em>Address<\/em> entity had any other method whose name started with \u201cget\u201d, then we needed to apply <em>@Transient<\/em> on it.<\/li>\n<\/ol>\n<p>If an entity has no explicit access mode information, just like our <em>Address<\/em> entity that we created in the <a title=\"JPA tutorial: Mapping Entities \u2013 Part 1\" href=\"http:\/\/www.javacodegeeks.com\/2014\/09\/jpa-tutorial-mapping-entities-part-1.html\">first part of this series<\/a>, then JPA assumes a default access mode. This assumption is not made at random. Instead, JPA first tries to figure out the location of the <em>@Id<\/em> annotation. If the <em>@Id<\/em> annotation is used on a field, then field access mode is assumed. If the <em>@Id<\/em> annotation is used on a getter method, then property access mode is assumed. So even if we remove the <i>@Access<\/i> annotation from the\u00a0<em>Address<\/em> entity in the above example the mapping will still be valid and JPA will assume property access mode:<\/p>\n<pre class=\" brush:java\">@Entity\r\n@Table(name = \"tbl_address\")\r\npublic class Address {\r\n  private Integer id;\r\n  private String street;\r\n  private String city;\r\n  private String province;\r\n  private String country;\r\n  private String postcode;\r\n  private String transientColumn;\r\n\r\n  @Id\r\n  @GeneratedValue\r\n  @Column(name = \"address_id\")\r\n  public Integer getId() {\r\n    return id;\r\n  }\r\n\r\n  \/\/ Rest of the class........<\/pre>\n<p>Some important points to remember about the access modes:<\/p>\n<ol>\n<li>You should never\u00a0declare a field as <em>public<\/em> if you use field access mode. All fields of the entity\u00a0should\u00a0have\u00a0either <em>private<\/em> (best!), <em>protected<\/em> or default access type. The reason behind this is that declaring the fields as <em>public<\/em> will allow any unprotected\u00a0class to directly access the entity states which could defeat the provider implementation easily. For example, suppose that you have an entity whose fields are all public. Now if this entity is a managed entity (which means it has been saved into the database) and any other class changes the value of its\u00a0<em>id<\/em>, and then you try to save the changes back to the database, you may face unpredictable behaviors (I will try to elaborate on this topic in a future article). Even the entity class itself should only manipulate the fields directly during initialization (i.e., inside the constructors).<\/li>\n<li>In case of property access mode, if we apply the annotations on the setter methods rather than on the getter methods, then they will simply be ignored.<\/li>\n<\/ol>\n<p>It\u2019s also possible to mix both of these access types. Suppose that you want to use field access mode\u00a0for all but one state of an entity, and for that one remaining state you would like to use property access mode because you want\u00a0to perform some conversion before writing\/after reading the state value to and from the database. You can do this easily by following the steps below:<\/p>\n<ol>\n<li>Mark the entity with the\u00a0<em>@Access<\/em> annotation and specify <i>AccessType.FIELD<\/i>\u00a0as the access mode for all the fields.<\/li>\n<li>Mark the field for which you do not like to use the field access mode with the <i>@Transient<\/i> annotation.<\/li>\n<li>Mark the getter method of the property with the <i>@Access<\/i> annotation and specify\u00a0<i>AccessType.PROPERTY<\/i>\u00a0as the access mode.<\/li>\n<\/ol>\n<p>The following example demonstrates this approach as the\u00a0<em>postcode<\/em> has been changed to use property access mode:<\/p>\n<pre class=\" brush:java\">@Entity\r\n@Table(name = \"tbl_address\")\r\n@Access(AccessType.FIELD)\r\npublic class Address {\r\n  @Id\r\n  @GeneratedValue\r\n  @Column(name = \"address_id\")\r\n  private Integer id;\r\n\r\n  private String street;\r\n  private String city;\r\n  private String province;\r\n  private String country;\r\n \r\n  \/**\r\n    * postcode is now marked as Transient\r\n    *\/\r\n  @Transient\r\n  private String postcode;\r\n \r\n  @Transient\r\n  private String transientColumn;\r\n\r\n  public Integer getId() {\r\n    return id;\r\n  }\r\n\r\n  public Address setId(Integer id) {\r\n    this.id = id;\r\n    return this;\r\n  }\r\n\r\n  public String getStreet() {\r\n    return street;\r\n  }\r\n\r\n  public Address setStreet(String street) {\r\n    this.street = street;\r\n    return this;\r\n  }\r\n\r\n  public String getCity() {\r\n    return city;\r\n  }\r\n\r\n  public Address setCity(String city) {\r\n    this.city = city;\r\n    return this;\r\n  }\r\n\r\n  public String getProvince() {\r\n    return province;\r\n  }\r\n\r\n  public Address setProvince(String province) {\r\n    this.province = province;\r\n    return this;\r\n  }\r\n\r\n  public String getCountry() {\r\n    return country;\r\n  }\r\n\r\n  public Address setCountry(String country) {\r\n    this.country = country;\r\n    return this;\r\n  }\r\n\r\n  \/**\r\n    * We are now using property access mode for reading\/writing\r\n    * postcode\r\n    *\/\r\n  @Access(AccessType.PROPERTY)\r\n  public String getPostcode() {\r\n    return postcode;\r\n  }\r\n\r\n  public Address setPostcode(String postcode) {\r\n    this.postcode = postcode;\r\n    return this;\r\n  }\r\n}<\/pre>\n<p>The important thing to note here is that if we do not annotate the class with the\u00a0<em>@Access<\/em> annotation to explicitly specify the field access mode as the default one, and we annotate both the fields and the getter methods, then the resultant behavior of the mapping will be undefined. Which means the outcome will totally depend on the persistence provider i.e., one provider might choose to use the field access mode as default, one might use property access mode, or one might decide to throw an exception!<\/p>\n<p>That\u2019s it for today. If you find any problems\/have any questions, please do not hesitate to comment!<\/p>\n<p>Until next time.<\/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.codesod.com\/2014\/10\/13\/jpa-tutorial-mapping-entities-part-3\/\">JPA Tutorial: Mapping Entities \u2013 Part 3<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\/\">JCG partner<\/a> Sayem Ahmed at the <a href=\"http:\/\/www.codesod.com\/\">Codesod<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In my last article I showed two different ways to read\/write\u00a0persistent entity state\u00a0\u2013 field and property. When field access mode\u00a0is used, JPA directly reads the state values from the fields of an entity using reflection. It directly translates the field names into database column names if we do not specify the column names explicitly. \u00a0In &hellip;<\/p>\n","protected":false},"author":474,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[33],"class_list":["post-31623","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 Tutorial: Mapping Entities \u2013 Part 3<\/title>\n<meta name=\"description\" content=\"In my last article I showed two different ways to read\/write\u00a0persistent entity state\u00a0\u2013 field and property. When field access mode\u00a0is used, JPA directly\" \/>\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\/10\/jpa-tutorial-mapping-entities-part-3.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JPA Tutorial: Mapping Entities \u2013 Part 3\" \/>\n<meta property=\"og:description\" content=\"In my last article I showed two different ways to read\/write\u00a0persistent entity state\u00a0\u2013 field and property. When field access mode\u00a0is used, JPA directly\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.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:published_time\" content=\"2014-10-15T04:00:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-08-28T08:15:55+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=\"MD Sayem Ahmed\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@say3mbd\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"MD Sayem Ahmed\" \/>\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\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html\"},\"author\":{\"name\":\"MD Sayem Ahmed\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c28c3b2d8f198300d25627addda7df17\"},\"headline\":\"JPA Tutorial: Mapping Entities \u2013 Part 3\",\"datePublished\":\"2014-10-15T04:00:35+00:00\",\"dateModified\":\"2015-08-28T08:15:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html\"},\"wordCount\":854,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.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\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html\",\"name\":\"JPA Tutorial: Mapping Entities \u2013 Part 3\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2014-10-15T04:00:35+00:00\",\"dateModified\":\"2015-08-28T08:15:55+00:00\",\"description\":\"In my last article I showed two different ways to read\\\/write\u00a0persistent entity state\u00a0\u2013 field and property. When field access mode\u00a0is used, JPA directly\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/10\\\/jpa-tutorial-mapping-entities-part-3.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\\\/10\\\/jpa-tutorial-mapping-entities-part-3.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 Tutorial: Mapping Entities \u2013 Part 3\"}]},{\"@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\\\/c28c3b2d8f198300d25627addda7df17\",\"name\":\"MD Sayem Ahmed\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cb149440e74e234a74de8359fb6164f93a29b69a2a1980b6cebe5afd7f841fa7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cb149440e74e234a74de8359fb6164f93a29b69a2a1980b6cebe5afd7f841fa7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cb149440e74e234a74de8359fb6164f93a29b69a2a1980b6cebe5afd7f841fa7?s=96&d=mm&r=g\",\"caption\":\"MD Sayem Ahmed\"},\"description\":\"Sayem is an experienced software developer who loves to work with anything related to the internet. He has worked in various domains using a large number of programming languages. Although he specially likes to work with Java and JavaScript, he enjoys working with other languages too.\",\"sameAs\":[\"https:\\\/\\\/www.sayemahmed.com\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sayem64\",\"https:\\\/\\\/x.com\\\/say3mbd\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/sayem-ahmed\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JPA Tutorial: Mapping Entities \u2013 Part 3","description":"In my last article I showed two different ways to read\/write\u00a0persistent entity state\u00a0\u2013 field and property. When field access mode\u00a0is used, JPA directly","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\/10\/jpa-tutorial-mapping-entities-part-3.html","og_locale":"en_US","og_type":"article","og_title":"JPA Tutorial: Mapping Entities \u2013 Part 3","og_description":"In my last article I showed two different ways to read\/write\u00a0persistent entity state\u00a0\u2013 field and property. When field access mode\u00a0is used, JPA directly","og_url":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-10-15T04:00:35+00:00","article_modified_time":"2015-08-28T08:15:55+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":"MD Sayem Ahmed","twitter_card":"summary_large_image","twitter_creator":"@say3mbd","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"MD Sayem Ahmed","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html"},"author":{"name":"MD Sayem Ahmed","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c28c3b2d8f198300d25627addda7df17"},"headline":"JPA Tutorial: Mapping Entities \u2013 Part 3","datePublished":"2014-10-15T04:00:35+00:00","dateModified":"2015-08-28T08:15:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html"},"wordCount":854,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.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\/10\/jpa-tutorial-mapping-entities-part-3.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html","url":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html","name":"JPA Tutorial: Mapping Entities \u2013 Part 3","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2014-10-15T04:00:35+00:00","dateModified":"2015-08-28T08:15:55+00:00","description":"In my last article I showed two different ways to read\/write\u00a0persistent entity state\u00a0\u2013 field and property. When field access mode\u00a0is used, JPA directly","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/10\/jpa-tutorial-mapping-entities-part-3.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\/10\/jpa-tutorial-mapping-entities-part-3.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 Tutorial: Mapping Entities \u2013 Part 3"}]},{"@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\/c28c3b2d8f198300d25627addda7df17","name":"MD Sayem Ahmed","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cb149440e74e234a74de8359fb6164f93a29b69a2a1980b6cebe5afd7f841fa7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cb149440e74e234a74de8359fb6164f93a29b69a2a1980b6cebe5afd7f841fa7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb149440e74e234a74de8359fb6164f93a29b69a2a1980b6cebe5afd7f841fa7?s=96&d=mm&r=g","caption":"MD Sayem Ahmed"},"description":"Sayem is an experienced software developer who loves to work with anything related to the internet. He has worked in various domains using a large number of programming languages. Although he specially likes to work with Java and JavaScript, he enjoys working with other languages too.","sameAs":["https:\/\/www.sayemahmed.com\/","https:\/\/www.linkedin.com\/in\/sayem64","https:\/\/x.com\/say3mbd"],"url":"https:\/\/www.javacodegeeks.com\/author\/sayem-ahmed"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/31623","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\/474"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=31623"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/31623\/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=31623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=31623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=31623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}