{"id":4917,"date":"2018-08-21T12:51:29","date_gmt":"2018-08-21T07:21:29","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=4917"},"modified":"2018-08-21T12:51:49","modified_gmt":"2018-08-21T07:21:49","slug":"hibernate-mapping","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/","title":{"rendered":"Hibernate Mapping"},"content":{"rendered":"<p style=\"text-align: justify;\">Hibernate mappings are one of the key features of\u00a0\u00a0<a href=\"http:\/\/www.hibernate.org\/\" rel=\"nofollow\">Hibernate<\/a>. They establish the relationship between two database tables as attributes in your model. That allows you to easily navigate the associations in your model and Criteria queries.<\/p>\n<p style=\"text-align: justify;\">You can establish either unidirectional or bidirectional i.e you can either model them as an attribute on only one of the associated entities or on both. It will not impact your database mapping tables, but it defines in which direction you can use the relationship in your model and\u00a0 Criteria queries.<\/p>\n<p>The relationship that can be established between entities are-<\/p>\n<ul>\n<li><strong>One To One<\/strong> &#8211; It represent one to one relationship between two tables.<\/li>\n<li><strong>One To Many\/Many To one<\/strong> &#8211; It represents the one to many relationship between two tables.<\/li>\n<li><strong>Many To Many<\/strong> &#8211; It represents thew many to many relationship between two tables.<\/li>\n<\/ul>\n<p>You all must have heard about these relationship. In this blog, you will learn about all relationship using Hibernate.<\/p>\n<h3><strong>One to One<\/strong><\/h3>\n<p>There is <strong><em>One to One<\/em><\/strong> relationship between <em>Address<\/em>. Although Address must not be an Entity as it is a value type but for this Example we will consider <em>Address <\/em>as a separate Entity.<\/p>\n<p style=\"text-align: justify;\">For <em><strong>One to One<\/strong><\/em> relationship, we need to simply annotate the data member of the corresponding class with <strong>@OneToOne.\u00a0<\/strong>After running the application if we look after the table created by the hibernate , we will found that the <em>user_details <\/em>table has all the field i.e <strong>id<\/strong> , <strong>userName<\/strong> along with a foreign key of <em>address<\/em> table column ( In this example ). If we want to acheive two way binding like <em>User<\/em> object should have <em>Address<\/em> and viceversa. Then we have to make the User object inside Address class and annotate it with\u00a0<strong>@OneToOne. <\/strong>Then, the address table will also contain the foreign key of user column.<\/p>\n<p>You will see the name of field in both the table will be default depending on table name but to change the default implementation , we have to annotate it with <strong>@JoinColumn\u00a0 <\/strong>with a attribute <strong>name.<\/strong><\/p>\n<p><strong>Address.java<\/strong><\/p>\n<pre class=\"lang:default decode:true\">package com.innovatnm.demohibernate.model;\r\n\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.OneToOne;\r\n\r\n@Entity\r\npublic class Address {\r\n\t\r\n\t@Id @GeneratedValue\r\n\tprivate int id;\r\n\tprivate String street;\r\n\tprivate String city;\r\n\t@OneToOne(mappedBy=\"address\")\r\n\tprivate User user;\r\n\t\r\n\tpublic Address() {}\r\n\tpublic Address(int id, String street, String city) {\r\n\t\tthis.id = id;\r\n\t\tthis.street = street;\r\n\t\tthis.city = city;\r\n\t}\r\n\r\n\tpublic String getStreet() {\r\n\t\treturn street;\r\n\t}\r\n\t\r\n\tpublic void setStreet(String street) {\r\n\t\tthis.street = street;\r\n\t}\r\n\t\r\n\tpublic String getCity() {\r\n\t\treturn city;\r\n\t}\r\n\r\n\tpublic User getUser() {\r\n\t\treturn user;\r\n\t}\r\n\r\n\tpublic void setUser(User user) {\r\n\t\tthis.user = user;\r\n\t}\r\n\r\n\tpublic void setCity(String city) {\r\n\t\tthis.city = city;\r\n\t}\r\n\r\n\tpublic int getId() {\r\n\t\treturn id;\r\n\t}\r\n\r\n\tpublic void setId(int id) {\r\n\t\tthis.id = id;\r\n\t}\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>One to Many\/Many to One<\/h3>\n<p>There is <em><strong>One to Many<\/strong><\/em> relationship between <em>User <\/em>and <em>Mobile <\/em>. As one user can have more than one Mobile . And<em><strong> Many to One<\/strong><\/em> relationship between <em>Mobile <\/em>and <em>User<\/em><strong>.<\/strong><\/p>\n<p style=\"text-align: justify;\">For <em><strong>One to Many<\/strong><\/em> relationship , we have to annotate in same manner as above with <strong>@OneToMany <\/strong>to collection type data member<strong>.\u00a0<\/strong>After running the application if we look after the table created by the hibernate , we will found that the hibernate is making a new table for mapping of <em>user_details <\/em>table and <em>mobile<\/em> table( In this example ). For two way binding we annotate the <em>user<\/em> inside the <i>Mobile\u00a0<\/i>class with <strong>@ManyToOne.\u00a0<\/strong><\/p>\n<p style=\"text-align: justify;\">You will see the mapping table and its column name will have default name generated based on the two tables but to change the default implementation, we will annotate it <strong>@JoinTable <\/strong>and the attribute <em>name<\/em> in this is to change the name of mapping table and attribute\u00a0<em>joinColumns<\/em> for the primary key of the same class ( <em>User<\/em> in this case ) and\u00a0<em>inverseJoinColumns\u00a0<\/em>for the primary key of corresponding class ( <i>Mobile\u00a0<\/i>in this case ).<\/p>\n<p><strong>Mobile.java<\/strong><\/p>\n<pre class=\"lang:default decode:true\">package com.innovatnm.demohibernate.model;\r\n\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.JoinColumn;\r\nimport javax.persistence.ManyToOne;\r\n\r\n@Entity\r\npublic class Mobile {\r\n\t@Id @GeneratedValue\r\n\tprivate int id;\r\n\tprivate String brand;\r\n\tprivate String model;\r\n\t\r\n\t@ManyToOne\r\n\t@JoinColumn(name=\"user_id\")\r\n\tprivate User user;\r\n\t\r\n\tpublic int getId() {\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(int id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic String getBrand() {\r\n\t\treturn brand;\r\n\t}\r\n\tpublic void setBrand(String brand) {\r\n\t\tthis.brand = brand;\r\n\t}\r\n\tpublic String getModel() {\r\n\t\treturn model;\r\n\t}\r\n\tpublic void setModel(String model) {\r\n\t\tthis.model = model;\r\n\t}\r\n\tpublic User getUser() {\r\n\t\treturn user;\r\n\t}\r\n\tpublic void setUser(User user) {\r\n\t\tthis.user = user;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<h3><\/h3>\n<h3><strong>Many to Many<\/strong><\/h3>\n<p style=\"text-align: justify;\">There is <em><strong>Many to Many<\/strong><\/em> relationship between <em>User <\/em>and <em>Vehicle<\/em>. We will let consider a world where there is multiple owner of a <em>Vehicle <\/em>and A owner can also own multiple <em>Vehicle<\/em>. You can consider that the <em>Vehicle <\/em>is used for the rent and one <em>User <\/em>can rent multiple <em>Vehicle <\/em>and a <em>Vehicle <\/em>can be rented by multiple <em>Users<\/em>.<em>\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\">For <em><strong>Many to Many\u00a0<\/strong><\/em>relationship , we have to annotate in same manner as above with <strong>@ManyToMany <\/strong>to collection type data member and for two way binding we have to do the same in the corresponding class.\u00a0After running the application if we look after the table created by the hibernate , we will found that the there is two mapping table formed one made by first mapping\u00a0 ( by <em>User<\/em> in this case ) and other mapping table by <em>Vehicle<\/em> class. So, In order to restrict it, we have to tell hibernate that the mapping is already done by other class with the help of attribute\u00a0<strong>mappedBy <\/strong>in\u00a0<strong>@ManyToMany.\u00a0<\/strong>So, we will add this attribute in either of the class <em>User<\/em> or <em>Vehicle.<\/em><\/p>\n<p><strong>Vehicle.java<\/strong><\/p>\n<pre class=\"lang:default decode:true\">package com.innovatnm.demohibernate.model;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Collection;\r\n\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.GenerationType;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.ManyToMany;\r\n\r\n@Entity\r\npublic class Vehicle {\r\n\t\r\n\t@Id\r\n\t@GeneratedValue(strategy=GenerationType.AUTO)\r\n\tprivate int id;\r\n\tprivate String name;\r\n\t\r\n\t@ManyToMany(mappedBy=\"vehicle\")\r\n\tprivate Collection&lt;User&gt; user=new ArrayList&lt;&gt;();;\r\n\r\n\r\n\tpublic int getId() {\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(int id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\tpublic Collection&lt;User&gt; getUser() {\r\n\t\treturn user;\r\n\t}\r\n\tpublic void setUser(Collection&lt;User&gt; user) {\r\n\t\tthis.user = user;\r\n\t}\r\n}\r\n<\/pre>\n<p>Now , After looking upto <em>User<\/em> class you will got to understand things clearly . So here is <em>User<\/em> class<\/p>\n<p><strong>User.java<\/strong><\/p>\n<pre class=\"lang:default decode:true\">package com.innovatnm.demohibernate.model;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Collection;\r\n\r\nimport javax.persistence.CascadeType;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.GenerationType;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.JoinColumn;\r\nimport javax.persistence.JoinTable;\r\nimport javax.persistence.ManyToMany;\r\nimport javax.persistence.OneToMany;\r\nimport javax.persistence.OneToOne;\r\nimport javax.persistence.Table;\r\n\r\n@Entity\r\n@Table(name=\"user_details\")\r\npublic class User {\r\n\t\r\n\t@GeneratedValue(strategy=GenerationType.AUTO)\r\n\t@Id\r\n\tprivate int id;\r\n\tprivate String userName;\r\n\t\r\n\t@ManyToMany(cascade=CascadeType.ALL)\r\n\t@JoinTable(name=\"usr_vehicle\",joinColumns=@JoinColumn(name=\"user_id\"),inverseJoinColumns=@JoinColumn(name=\"vehicle_id\") )\r\n\tprivate Collection&lt;Vehicle&gt; vehicle=new ArrayList&lt;&gt;();\r\n\t\r\n\t@OneToOne(cascade=CascadeType.ALL)\r\n\t@JoinColumn(name=\"address_id\")\r\n\tprivate Address address;\r\n\t\r\n\t@OneToMany(cascade=CascadeType.ALL)\r\n\t@JoinTable(name=\"user_mobile_mapping\",joinColumns=@JoinColumn(name=\"user_id\"),inverseJoinColumns=@JoinColumn(name=\"mobile_id\"))\r\n\tprivate Collection&lt;Mobile&gt; mobile=new ArrayList&lt;&gt;();;\r\n\t\r\n\r\n\tpublic Collection&lt;Mobile&gt; getMobile() {\r\n\t\treturn mobile;\r\n\t}\r\n\tpublic void setMobile(Collection&lt;Mobile&gt; mobile) {\r\n\t\tthis.mobile = mobile;\r\n\t}\r\n\tpublic Collection&lt;Vehicle&gt; getVehicle() {\r\n\t\treturn vehicle;\r\n\t}\r\n\tpublic void setVehicle(Collection&lt;Vehicle&gt; vehicle) {\r\n\t\tthis.vehicle = vehicle;\r\n\t}\r\n\tpublic Address getAddress() {\r\n\t\treturn address;\r\n\t}\r\n\tpublic void setAddress(Address address) {\r\n\t\tthis.address = address;\r\n\t}\r\n\tpublic int getId() {\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(int id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic String getUserName() {\r\n\t\treturn userName;\r\n\t}\r\n\tpublic void setUserName(String userName) {\r\n\t\tthis.userName = userName;\r\n\t}\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>HibernateMain.java<\/strong><\/p>\n<pre class=\"lang:default decode:true\">package com.innovatnm.demohibernate;\r\n\r\nimport org.hibernate.Session;\r\nimport org.hibernate.SessionFactory;\r\nimport org.hibernate.cfg.Configuration;\r\n\r\nimport com.innovatnm.demohibernate.model.Address;\r\nimport com.innovatnm.demohibernate.model.Mobile;\r\nimport com.innovatnm.demohibernate.model.User;\r\nimport com.innovatnm.demohibernate.model.Vehicle;\r\n\r\npublic class HibernateMain {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tUser user=new User();\r\n\t\tUser user2=new User();\r\n\t\tuser2.setUserName(\"Dev\");\r\n\t\tuser.setUserName(\"Ankit\");\r\n\t\t\r\n\t\tAddress address= new Address();\r\n\t\taddress.setStreet(\"sector 15\");\r\n\t\taddress.setCity(\"noida\");\r\n\t\tAddress address2=new Address();\r\n\t\taddress2.setCity(\"Muzaffarpur\");\r\n\t\taddress2.setStreet(\"sahebganj\");\r\n\t\t\r\n\t\t\r\n\t\tVehicle veh=new Vehicle();\r\n\t\tveh.setName(\"car\");\r\n\t\tVehicle vehicle=new Vehicle();\r\n\t\tvehicle.setName(\"jeep\");\r\n\t\tVehicle vehicle2= new Vehicle();\r\n\t\tvehicle2.setName(\"Bike\");\r\n\t\tVehicle vehicle3= new Vehicle();\r\n\t\tvehicle3.setName(\"Bus\");\r\n\t\tVehicle vehicle4=new Vehicle();\r\n\t\tvehicle4.setName(\"cycle\");\r\n\t\tVehicle vehicle5= new Vehicle();\r\n\t\tvehicle5.setName(\"Truck\");\r\n\t\t\r\n\t\tMobile mobile =new Mobile();\r\n\t\tmobile.setBrand(\"sony\");\r\n\t\tmobile.setModel(\"xperia z3\");\r\n\t\tMobile mobile2 = new Mobile();\r\n\t\tmobile2.setBrand(\"Redmi\");\r\n\t\tmobile2.setModel(\"Note 5 pro\");\r\n\t\tMobile mobile3 = new Mobile();\r\n\t\tmobile3.setBrand(\"Nokia\");\r\n\t\tmobile3.setModel(\"7 plus\");\r\n\t\t\r\n\t\tuser.setAddress(address);\r\n\t\tuser2.setAddress(address2);\r\n\t\taddress.setUser(user);\r\n\t\taddress2.setUser(user2);\r\n\t\t\r\n\t\tuser.getMobile().add(mobile);\r\n\t\tuser.getMobile().add(mobile2);\r\n\t\tmobile.setUser(user);\r\n\t\tmobile2.setUser(user);\r\n\t\tuser2.getMobile().add(mobile3);\r\n\t\tmobile3.setUser(user2);\r\n\t\t\r\n\t\tuser.getVehicle().add(veh);\r\n\t\tuser.getVehicle().add(vehicle);\r\n\t\tuser.getVehicle().add(vehicle2);\r\n\t\tveh.getUser().add(user);\r\n\t\tvehicle.getUser().add(user);\r\n\t\tvehicle2.getUser().add(user);\r\n\t\tuser2.getVehicle().add(vehicle3);\r\n\t\tuser2.getVehicle().add(vehicle4);\r\n\t\tuser2.getVehicle().add(vehicle5);\r\n\t\tvehicle3.getUser().add(user2);\r\n\t\tvehicle4.getUser().add(user2);\r\n\t\tvehicle5.getUser().add(user2);\r\n\t\t\r\n\t\t\r\n\t\tSessionFactory sf=new Configuration().configure().buildSessionFactory();\r\n\t\tSession session=sf.openSession();\r\n\t\tsession.beginTransaction();\r\n\t\tsession.save(user);\r\n\t\tsession.save(user2);\r\n\t\tsession.getTransaction().commit();\r\n\t\tsession.close();\r\n\t}\r\n}<\/pre>\n<p>After executing the main class you will found the table as:<\/p>\n<p>address table<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4934\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/address.jpg\" alt=\"\" width=\"202\" height=\"49\" \/><\/p>\n<p>mobile table<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4935\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/mobile.jpg\" alt=\"\" width=\"207\" height=\"64\" \/><\/p>\n<p>user_details table<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4936\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/user.jpg\" alt=\"\" width=\"196\" height=\"46\" \/><\/p>\n<p>usr_vehicle table<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4937\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/useveh.jpg\" alt=\"\" width=\"147\" height=\"110\" \/><\/p>\n<p>user_mobile_mapping table<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4938\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/usemob.jpg\" alt=\"\" width=\"136\" height=\"64\" \/><\/p>\n<p>vehicle table<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4939\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/vehicle.jpg\" alt=\"\" width=\"111\" height=\"109\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/vehicle.jpg 111w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/vehicle-24x24.jpg 24w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/vehicle-48x48.jpg 48w\" sizes=\"(max-width: 111px) 100vw, 111px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>You can download the code :\u00a0 \u00a0 \u00a0<a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/demohibernate.zip\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4943\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/download.png\" alt=\"\" width=\"29\" height=\"29\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/download.png 225w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/download-150x150.png 150w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/download-24x24.png 24w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/download-48x48.png 48w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/07\/download-96x96.png 96w\" sizes=\"(max-width: 29px) 100vw, 29px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hibernate mappings are one of the key features of\u00a0\u00a0Hibernate. They establish the relationship between two database tables as attributes in your model. That allows you to easily navigate the associations in your model and Criteria queries. You can establish either unidirectional or bidirectional i.e you can either model them as an attribute on only one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4999,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[256,263],"tags":[265,280,59],"class_list":["post-4917","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-application","category-orm","tag-hibernate","tag-web-application","tag-webservice"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Hibernate Mapping - InnovationM - Blog<\/title>\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.innovationm.com\/blog\/hibernate-mapping\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hibernate Mapping - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"Hibernate mappings are one of the key features of\u00a0\u00a0Hibernate. They establish the relationship between two database tables as attributes in your model. That allows you to easily navigate the associations in your model and Criteria queries. You can establish either unidirectional or bidirectional i.e you can either model them as an attribute on only one [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-21T07:21:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-08-21T07:21:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/08\/Hibernate-Mapping.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1140\" \/>\n\t<meta property=\"og:image:height\" content=\"633\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Hibernate Mapping\",\"datePublished\":\"2018-08-21T07:21:29+00:00\",\"dateModified\":\"2018-08-21T07:21:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/\"},\"wordCount\":764,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/Hibernate-Mapping.png\",\"keywords\":[\"Hibernate\",\"Web Application\",\"WebService\"],\"articleSection\":[\"Java Application\",\"ORM\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/\",\"name\":\"Hibernate Mapping - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/Hibernate-Mapping.png\",\"datePublished\":\"2018-08-21T07:21:29+00:00\",\"dateModified\":\"2018-08-21T07:21:49+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/Hibernate-Mapping.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/Hibernate-Mapping.png\",\"width\":1140,\"height\":633},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/hibernate-mapping\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hibernate Mapping\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hibernate Mapping - InnovationM - Blog","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.innovationm.com\/blog\/hibernate-mapping\/","og_locale":"en_US","og_type":"article","og_title":"Hibernate Mapping - InnovationM - Blog","og_description":"Hibernate mappings are one of the key features of\u00a0\u00a0Hibernate. They establish the relationship between two database tables as attributes in your model. That allows you to easily navigate the associations in your model and Criteria queries. You can establish either unidirectional or bidirectional i.e you can either model them as an attribute on only one [&hellip;]","og_url":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/","og_site_name":"InnovationM - Blog","article_published_time":"2018-08-21T07:21:29+00:00","article_modified_time":"2018-08-21T07:21:49+00:00","og_image":[{"width":1140,"height":633,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/08\/Hibernate-Mapping.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Hibernate Mapping","datePublished":"2018-08-21T07:21:29+00:00","dateModified":"2018-08-21T07:21:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/"},"wordCount":764,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/08\/Hibernate-Mapping.png","keywords":["Hibernate","Web Application","WebService"],"articleSection":["Java Application","ORM"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/","url":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/","name":"Hibernate Mapping - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/08\/Hibernate-Mapping.png","datePublished":"2018-08-21T07:21:29+00:00","dateModified":"2018-08-21T07:21:49+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/08\/Hibernate-Mapping.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/08\/Hibernate-Mapping.png","width":1140,"height":633},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/hibernate-mapping\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Hibernate Mapping"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/4917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=4917"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/4917\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/4999"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=4917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=4917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=4917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}