{"id":3460,"date":"2013-10-01T13:34:05","date_gmt":"2013-10-01T08:04:05","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=3460"},"modified":"2013-10-01T13:34:05","modified_gmt":"2013-10-01T08:04:05","slug":"introduction-hibernate","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/hibernate\/introduction-hibernate\/","title":{"rendered":"Introduction to Hibernate"},"content":{"rendered":"<p>Post by &#8211; <a title=\"Subhash Bhajankar Linkedin Profile\" href=\"http:\/\/www.linkedin.com\/pub\/subhash-bhajankar\/38\/a53\/1a8\">Subhash Bhajankar<\/a><\/p>\n<p><b>What is the problem that hibernate is trying to solve?<\/b><\/p>\n<p style=\"text-align: justify;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Let&#8217;s take an example of simple class that you have in your application. Referring Image 1, we have Employee object in our java class which has six fields. In our running application We would have lots of such objects in memory, What if I restart my application ? Everything will be lost. So to overcome this problem and persist data inside my application i will save it in Database.<\/p>\n<p style=\"text-align: justify;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0As shown in below image every object in Java will be represented as single row. Here, class corresponds to table and object of class corresponds to row. This was something that we were been doing over the year (Off course before ORM Tool).<\/p>\n<p style=\"text-align: justify;\">Normal approach to save data in Java is something like :<\/p>\n<ol>\n<li>Create JDBC Connection<\/li>\n<li>Connect Database<\/li>\n<li>Create SQL String dynamically by taking fields value one by one<\/li>\n<li>And also manage all transaction, Exception handling, rollback and commit<!--more--><\/li>\n<\/ol>\n<figure id=\"attachment_3463\" aria-describedby=\"caption-attachment-3463\" style=\"width: 624px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/problem.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-3463\" title=\"Necessity of Hibernate \" alt=\"Necessity of Hibernate \" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/problem.png?resize=624%2C251&#038;ssl=1\" width=\"624\" height=\"251\" \/><\/a><figcaption id=\"caption-attachment-3463\" class=\"wp-caption-text\">1. Necessity of Hibernate<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 So problem here is I have object here in java but I do not have objects here in Database\u00a0 level. So for saving I have to convert each object&#8217;s data into SQL query. Also for retrieving we have to do opposite like convert Record set into object. So at the end we are repeating converting Object data to SQL and SQL result to object.<\/p>\n<p style=\"text-align: justify;\">Wouldn&#8217;t it be great, if we have something, Some Tool, Some design pattern, which will take care of converting data between object and record?<\/p>\n<p style=\"text-align: left;\">If somehow, we try to create it by our own, We will face problems like :<\/p>\n<ol style=\"text-align: left;\">\n<li>Mapping member variables to columns<\/li>\n<li>Mapping relationship<\/li>\n<li>Handling data types<\/li>\n<li>Managing changes to object state<\/li>\n<li>Offcource Performance also \ud83d\ude42<\/li>\n<\/ol>\n<p style=\"text-align: left;\">To overcome all these problems we use <a title=\"ORM Tool\" href=\"http:\/\/en.wikipedia.org\/wiki\/Object-relational_mapping\">ORM tool<\/a> like <a title=\"Hibernate ORM Tool\" href=\"http:\/\/www.hibernate.org\/\">Hibernate <\/a>or <a title=\"Apache Ibatis ORM Tool\" href=\"http:\/\/attic.apache.org\/projects\/ibatis.html\">Ibatis<\/a><\/p>\n<figure id=\"attachment_3465\" aria-describedby=\"caption-attachment-3465\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/orm.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3465\" alt=\"ORM Tool\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/orm.png?resize=571%2C305&#038;ssl=1\" width=\"571\" height=\"305\" \/><\/a><figcaption id=\"caption-attachment-3465\" class=\"wp-caption-text\">2. ORM Tool &#8211; Mapped Object and Table<\/figcaption><\/figure>\n<p><strong>Advantages of Hibernate :<\/strong><\/p>\n<ol>\n<li>There are many advantages but I will list very few :<\/li>\n<li>One of Most common ORM accepted by Developers Community Worldwide<\/li>\n<li>Uses <a title=\"Java Persistence API\" href=\"http:\/\/www.oracle.com\/technetwork\/java\/javaee\/tech\/persistence-jsp-140049.html\">Java Persistance API (JPA)<\/a><\/li>\n<li>High Performance<\/li>\n<li>Reliability and Scalability<\/li>\n<li>Very easy to configure<\/li>\n<\/ol>\n<p>This is my first post, so please share your thoughts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post by &#8211; Subhash Bhajankar What is the problem that hibernate is trying to solve? \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Let&#8217;s take an example of simple class that you have in your application. Referring Image 1, we have Employee object in our java class which has six fields. In our running application We would have lots [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-3460","post","type-post","status-publish","format-standard","hentry","category-hibernate"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1643,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/servlet-hibernate-jquery-and-ajax-based-google-like-chat\/","url_meta":{"origin":3460,"position":0},"title":"Servlet, Hibernate, jQuery and Ajax based google like chat","author":"Jitendra","date":"March 14, 2011","format":false,"excerpt":"Servlet, Hibernate, jQuery and Ajax based google like chat with source code","rel":"","context":"In &quot;Hibernate&quot;","block_context":{"text":"Hibernate","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/hibernate\/"},"img":{"alt_text":"Servlet, Hibernate, jQuery and Ajax based google like chat","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Servlet-Hibernate-jQuery-and-Ajax-based-google-like-chat.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2347,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/hibernate\/step-by-step-hibernate-tutorial-using-eclipse-wtp\/","url_meta":{"origin":3460,"position":1},"title":"Step By Step Hibernate Tutorial Using eclipse WTP","author":"Jitendra","date":"August 8, 2011","format":false,"excerpt":"Step By Step Hibernate (ORM Tool) Tutorial Using eclipse WTP","rel":"","context":"In &quot;Hibernate&quot;","block_context":{"text":"Hibernate","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/hibernate\/"},"img":{"alt_text":"Eclipse Install New Software - Hibernate","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/08\/Eclipse-Install-New-Software-Hibernate.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1543,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/hibernate\/cause-and-solution-of-org-hibernate-lazyinitializationexception-could-not-initialize-proxy-no-session-error\/","url_meta":{"origin":3460,"position":2},"title":"Cause and solution of &#8220;org.hibernate.LazyInitializationException: could not initialize proxy &#8211; no Session&#8221; error","author":"Jitendra","date":"February 22, 2011","format":false,"excerpt":"Cause and solution of \"org.hibernate.LazyInitializationException: could not initialize proxy - no Session\" error","rel":"","context":"In &quot;Hibernate&quot;","block_context":{"text":"Hibernate","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/hibernate\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1467,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/difference-between-servletcontext-and-servletconfig\/","url_meta":{"origin":3460,"position":3},"title":"Difference between servletContext and ServletConfig","author":"Jitendra","date":"February 8, 2011","format":false,"excerpt":"What is difference between servletContext and ServletConfig?","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1612,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/serialization-marshalling-deflating-in-java\/","url_meta":{"origin":3460,"position":4},"title":"Serialization \/ Marshalling \/ Deflating in JAVA","author":"Jitendra","date":"March 9, 2011","format":false,"excerpt":"Concept of Serialization \/ Marshalling \/ Deflating in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Serialization ,Marshalling ,deflating, DeSerialization ,UnMarshalling ,inflating","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Serialization-Marshalling-deflating-DeSerialization-UnMarshalling-inflating.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3736,"url":"https:\/\/www.jitendrazaa.com\/blog\/others\/tips\/indexeddb-client-side-database\/","url_meta":{"origin":3460,"position":5},"title":"IndexedDB &#8211; Client Side Database","author":"Jitendra","date":"February 20, 2014","format":false,"excerpt":"One of many features of HTML5 is capability to store data on client machine with the help of \"Indexed Database API\". Using this technique web developers can add offline capabilities to their application. Currently almost every modern browser supports \"IndexedDB\". Unlike traditional RDBMS, IndexedDB doesn't have table or columns which\u2026","rel":"","context":"In &quot;HTML&quot;","block_context":{"text":"HTML","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/webtech\/web\/"},"img":{"alt_text":"HTML5 IndexedDB Demo","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/02\/HTML5-IndexedDB-Demo.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=3460"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3460\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=3460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=3460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=3460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}