<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6775105882860234755</id><updated>2024-11-01T16:02:00.139+05:30</updated><title type='text'>HIBERNATE 4U</title><subtitle type='html'>Hibernate frame work In java used for the ORM. It is one of the upcoming technology for DATA BASE CONNECTIVITY.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://hibernate4u.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6775105882860234755/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://hibernate4u.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Chandra</name><uri>http://www.blogger.com/profile/01209478501446255220</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6775105882860234755.post-963214025235658236</id><published>2010-07-07T16:05:00.010+05:30</published><updated>2011-07-17T11:51:21.303+05:30</updated><title type='text'>Hiber nate Tools Introduction:</title><content type='html'>&lt;g:plusone size=&quot;medium&quot;&gt;&lt;/g:plusone&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In this tutorial you will see how to persist the java objects using  the Hibernate Object/Relational Mapping (ORM) framework. Hibernate  automates ORM and considerably reduces the number of lines of code  needed to persist the object in the database. This example demonstrates  how to automatically generate code from the object/relational mapping  file, thus saving the developers time. This helps the developers to  focus on the business problem rather than doing repetitive coding work.                                                         &lt;br /&gt;
Hibernate uses XML document or the properties file to define the  object/relational mapping. The object/relational mapping file contains  the mapping between the Java object and the corresponding database  table. This example illustrates how to create the ORM using the XML  document.                                                        &lt;br /&gt;
First let&#39;s setup the environment. I am using  &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt; Eclipse IDE 3.4  &lt;/li&gt;
&lt;li&gt; Hibernate Core 3.3&lt;/li&gt;
&lt;li&gt; Hibernate Tools 3.2&lt;/li&gt;
&lt;li&gt; HSQLDB 1.8&lt;/li&gt;
&lt;/ul&gt;
You can download the Hibernate Core and Hibernate Tools &lt;a href=&quot;https://www.hibernate.org/6.html&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.  HyperSQL DataBase is a 100% lightweight Java SQL Database Engine. You  can download HSQLDB from this site&lt;a href=&quot;http://hsqldb.org/&quot; rel=&quot;nofollow&quot;&gt; http://hsqldb.org/ &lt;/a&gt;.                                                         &lt;br /&gt;
To install the Hibernate Tools, extract the &lt;i&gt;HibernateTools-3.X.zip&lt;/i&gt;  file and move all the files inside the features folder into the  features folder of the eclipse installation directory and  move all the  files inside the plugins folder into the plugins folder of the ecilpse  installation directory. Restart the eclipse.                                                         &lt;br /&gt;
First create a new Java project. Add the following lib files on the java  build path. &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_16745&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;01.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;antlr-2.7.6&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;02.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;commons-collections-3.1&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;03.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;dom4j-1.6.1&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;04.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;hibernate3&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;05.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;hsqldb&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;06.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;javassist-3.4.GA&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;07.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;jta-1.1&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;08.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;slf4j-api-1.5.6&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;09.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;slf4j-simple-1.5.6&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
The &lt;i&gt;hibernate3.jar&lt;/i&gt; contains all the core hibernate files. The &lt;i&gt;hsqldb.jar&lt;/i&gt;  is used, to connect with the HSQL database, if you are using someother  database then you need to include that jar file instead of this. The &lt;i&gt;slf4j-api-1.5.6  jar&lt;/i&gt; file is used for logging the informations, you can also use  other alternatives like log4j, to do that include that jar file instead  of &lt;i&gt;slf4j-simple-1.5.6&lt;/i&gt; jar file to your classpath.                                                         &lt;br /&gt;
Once you have installed the hibernate tools, you will have the option to  change to Hibernate prespective.  Go to &lt;i&gt;Window -&amp;gt; Open  Prespective -&amp;gt; Other&lt;/i&gt;, the following dialog box appears, select &lt;i&gt;Hibernate&lt;/i&gt;  and click the &lt;i&gt;Ok&lt;/i&gt; button.                                                         &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-1.gif&quot; /&gt; &lt;br /&gt;
Now let&#39;s see how to define the object/relational mapping using the  XML document. This  document has &lt;i&gt;hbm.xml&lt;/i&gt; extension. We will now  create the object/relational mapping for the simple class that holds  course related details. To do that create a package &lt;i&gt;com.vaannila.course&lt;/i&gt;  in the &lt;i&gt;src&lt;/i&gt; directory. The Hibernate XML mapping file will be  created in this directory. To create the mapping file, switch to  Hibernate prespective, right click the project folder and select &lt;i&gt;New  -&amp;gt; Hibernate XML Mapping File(hbm.xml) &lt;/i&gt;&lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-2.gif&quot; /&gt; &lt;br /&gt;
In the pop up window select the &lt;i&gt;course&lt;/i&gt; folder, enter the file  name as &lt;i&gt;Course.hbm.xml&lt;/i&gt; and click &lt;i&gt;Next&lt;/i&gt;. In the next  window click &lt;i&gt;Finish&lt;/i&gt;.                                                         &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-3.gif&quot; /&gt;  &lt;br /&gt;
Add the following code to the&lt;i&gt; Course.hbm.xml&lt;/i&gt; file.                                                         &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_921210&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;01.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;xml&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;version&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;1.0&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;?&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;02.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;03.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&quot;-//Hibernate/Hibernate  Mapping DTD 3.0//EN&quot;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;04.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;05.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;hibernate-mapping&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;06.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;07.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;class&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;com.vaannila.course.Course&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;table&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;COURSES&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;08.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;meta&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;attribute&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;class-description&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;09.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;This class  contains the course details.&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;10.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;meta&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;11.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;id&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;courseId&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;type&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;long&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;column&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;COURSE_ID&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;12.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;generator&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;class&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;native&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;/&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;13.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;id&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;14.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;courseName&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;type&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;string&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;column&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;COURSE_NAME&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;not-null&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;true&quot;&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;/&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;15.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;class&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;16.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;17.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;hibernate-mapping&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
The &lt;i&gt;hibernate-mapping&lt;/i&gt; element is the root element. The &lt;i&gt;class&lt;/i&gt;  element is used to map the Java class with the database table. The Java  class name is specified using the &lt;i&gt;name&lt;/i&gt; attribute of the &lt;i&gt;class&lt;/i&gt;  element and the database table name is specified using the &lt;i&gt;table&lt;/i&gt;  attribute of the &lt;i&gt;class&lt;/i&gt; element. The &lt;i&gt;meta&lt;/i&gt; element is  used to create the class description. The &lt;i&gt;id&lt;/i&gt; element is used to  create the primary key. The &lt;i&gt;name&lt;/i&gt; attribute of the &lt;i&gt;id&lt;/i&gt;  element refers to the property in the &lt;i&gt;Course&lt;/i&gt; class and the &lt;i&gt;column&lt;/i&gt;  attribute refers to the column in the &lt;i&gt;COURSES&lt;/i&gt; table. The &lt;i&gt;type&lt;/i&gt;  attribute holds the hibernate mapping type, this mapping types will  convert from Java to SQL data type and vice versa. The &lt;i&gt;generator&lt;/i&gt;  element within the &lt;i&gt;id&lt;/i&gt; element is used to automatically  generate the primary key values. When the &lt;i&gt;class&lt;/i&gt; attribute of  the generator element is set to &lt;i&gt;native, &lt;/i&gt;hibernate picks either &lt;i&gt;identity&lt;/i&gt;,  &lt;i&gt;sequence&lt;/i&gt; or &lt;i&gt;hilo&lt;/i&gt; algorithm depending upon the  capabilities of the  underlying database. The &lt;i&gt;property&lt;/i&gt; element is used to link a  property in the Java class to  a column in the database table.                                                         &lt;br /&gt;
The next step is to create the Hibernate configuration file. On  startup, Hibernate looks for a file called &lt;i&gt;hibernate.cfg.xml&lt;/i&gt; in  the root of the classpath. To create the Hibernate Configuration File,  right click the project, select &lt;i&gt;New -&amp;gt; Hibernate Configuration  File (cfg.xml)&lt;/i&gt; &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-4.gif&quot; /&gt; &lt;br /&gt;
By default the file name will be &lt;i&gt;hibernate.cfg.xml&lt;/i&gt;, select the &lt;i&gt;src&lt;/i&gt;  directory and click Next.                                                         &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-5.gif&quot; /&gt;  &lt;br /&gt;
Select the database dialect  as &lt;i&gt;HSQL&lt;/i&gt;. This property indicates  the particular SQL variant that Hibernate generates. Select the &quot;&lt;i&gt;org.hsqldb.jdbcDriver&lt;/i&gt;&quot;  option for the driver class. Enter the connection url &quot;&lt;i&gt;jdbc:hsqldb:hsql://localhost&lt;/i&gt;&quot;.  Enter the user name as &quot;&lt;i&gt;sa&lt;/i&gt;&quot; and click &lt;i&gt;Finish&lt;/i&gt;. These  properties specifies the necessary configuration for the JDBC  connection.                                                        &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-6.gif&quot; /&gt; &lt;br /&gt;
The &lt;i&gt;show_sql&lt;/i&gt; option, if set to true will display all the  executed SQL queries on the console.                                                         &lt;br /&gt;
The property &lt;i&gt;hbm2ddl.auto&lt;/i&gt;, if set to create, will drop and  re-create the database schema on startup. &lt;br /&gt;
In the end we add the &lt;i&gt;Course.hbm.xml&lt;/i&gt; file to the  configuration. The implementation of the &lt;i&gt;hibernate.cfg.xml&lt;/i&gt; file  is shown below. &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_630118&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;01.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;xml&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;version&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;1.0&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;encoding&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;UTF-8&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;?&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;02.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;03.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&quot;-//Hibernate/Hibernate  Configuration DTD 3.0//EN&quot;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;04.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&quot;http://hibernate.sourceforge.net/  hibernate-configuration-3.0.dtd&quot;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;05.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;hibernate-configuration&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;06.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;session-factory&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;07.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;hibernate.connection.driver_class&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt; org.hsqldb.jdbcDriver&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;08.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;hibernate.connection.url&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;  jdbc:hsqldb:hsql://localhost&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;09.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;hibernate.connection.username&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;sa&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;10.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;connection.password&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;11.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;connection.pool_size&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;1&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;12.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;hibernate.dialect&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;  org.hibernate.dialect.HSQLDialect&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;13.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;show_sql&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;true&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;14.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;hbm2ddl.auto&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;create&lt;code class=&quot;keyword&quot;&gt;property&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;15.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;mapping&lt;/code&gt;  &lt;code class=&quot;color1&quot;&gt;resource&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;com/vaannila/course/Course.hbm.xml&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;/&amp;gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;16.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;session-factory&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;17.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;hibernate-configuration&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
Once the Hibernate configuration file is created we need to create a  Hibernate console configuration. To do this right click the project  folder, select &lt;i&gt;New -&amp;gt; Hibernate Console Configuration&lt;/i&gt;.                                                         &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-7.gif&quot; /&gt; &lt;br /&gt;
The Hibernate Console configuration wizard appears. &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-8.gif&quot; /&gt;  &lt;br /&gt;
By default the wizard will load the Hibernate configuration file  information. Just click the &lt;i&gt;Finish&lt;/i&gt; button to create the  Hibernate console configuration.                                                         &lt;br /&gt;
Once the Hibernate console configuration is created, you can generate  code by selecting the &lt;i&gt;Hibernate Code Generation Configurations&lt;/i&gt;  option form the toolbar.                                                         &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-9.gif&quot; /&gt; &lt;br /&gt;
The Hibernate Code Generation wizard will be displayed. Now select  the output directory as the &lt;i&gt;src&lt;/i&gt; directory.                                                         &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-10.gif&quot; /&gt; &lt;br /&gt;
In the Exporters tag select the &quot;&lt;i&gt;Use Java 5 Syntax&lt;/i&gt;&quot; option and &quot;&lt;i&gt;Domain  Code(.java)&lt;/i&gt;&quot; option. &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-11.gif&quot; /&gt;  &lt;br /&gt;
In the Refresh tab select the options as shown below and click the &lt;i&gt;Run&lt;/i&gt;  button to generate the code.                                                         &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-12.gif&quot; /&gt; &lt;br /&gt;
The following &lt;i&gt;Course.java&lt;/i&gt; class will be generated from the&lt;i&gt;  Course.hbm.xml&lt;/i&gt; mapping file.                                                         &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_210914&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;01.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;package&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;com.vaannila.course;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;02.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;03.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;comments&quot;&gt;// Generated May 30, 2009 6:49:31 AM by Hibernate Tools  3.2.4.GA&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;04.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;05.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;comments&quot;&gt;/**&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;06.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;comments&quot;&gt;*   This  class contains the course details.&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;07.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;comments&quot;&gt;*   &lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;08.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;comments&quot;&gt;*/&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;09.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Course &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;implements&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;java.io.Serializable {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;10.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;11.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;private&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;long&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;courseId;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;12.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;private&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;String  courseName;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;13.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;14.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Course()  {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;15.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;16.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;17.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Course(String  courseName) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;18.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;this&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;.courseName = courseName;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;19.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;20.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;21.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;long&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;getCourseId() {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;22.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;this&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;.courseId;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;23.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;24.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;25.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;setCourseId(&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;long&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;courseId) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;26.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;this&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;.courseId  = courseId;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;27.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;28.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;29.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;String  getCourseName() {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;30.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;this&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;.courseName;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;31.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;32.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;33.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;setCourseName(String courseName) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;34.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;this&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;.courseName  = courseName;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;35.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;36.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;37.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
Now create the &lt;i&gt;HibernateUtil&lt;/i&gt; class. The &lt;i&gt;HibernateUtil&lt;/i&gt;  class helps in creating the &lt;i&gt;SessionFactory&lt;/i&gt; from the Hibernate  configuration file. The &lt;i&gt;SessionFactory&lt;/i&gt; is threadsafe, so it is  not necessary to obtain one for each thread. Here the static singleton  pattern is used to instantiate the &lt;i&gt;SessionFactory&lt;/i&gt;. The  implementation of the &lt;i&gt;HibernateUtil&lt;/i&gt; class is shown below.                                                         &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_682712&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;01.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;package&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;com.vaannila.util;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;02.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;03.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;import&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;org.hibernate.SessionFactory;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;04.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;import&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;org.hibernate.cfg.Configuration;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;05.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;06.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;HibernateUtil {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;07.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;private&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;static&lt;/code&gt;  &lt;code class=&quot;keyword&quot;&gt;final&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;SessionFactory  sessionFactory;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;08.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;static&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;09.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;try&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;10.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;sessionFactory  = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;new&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Configuration().configure()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;11.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;                    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 160px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;.buildSessionFactory();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;12.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;catch&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;(Throwable ex) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;13.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;System.err.println(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Initial SessionFactory creation failed.&quot;&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;+ ex);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;14.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;throw&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;new&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;ExceptionInInitializerError(ex);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;15.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;16.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;17.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;18.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;static&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;SessionFactory getSessionFactory() {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;19.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;sessionFactory;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;20.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;21.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&amp;nbsp; &lt;br /&gt;
Now we will create a class with the &lt;i&gt;main()&lt;/i&gt; method to run the  application.                                                        &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_948851&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;001.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;package&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;com.vaannila.course;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;002.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;003.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;import&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;java.util.List;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;004.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;import&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;java.util.Iterator;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;005.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;006.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;import&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;org.hibernate.HibernateException;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;007.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;import&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;org.hibernate.Session;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;008.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;import&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;org.hibernate.Transaction;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;009.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;010.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;import&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;com.vaannila.util.HibernateUtil;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;011.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;012.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Main {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;013.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;014.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;static&lt;/code&gt;  &lt;code class=&quot;keyword&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;main(String[]  args) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;015.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Main obj = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;new&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Main();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;016.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Long courseId1 = obj.saveCourse(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Physics&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;017.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Long courseId2 = obj.saveCourse(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Chemistry&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;018.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Long courseId3 = obj.saveCourse(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Maths&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;019.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;obj.listCourse();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;020.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;obj.updateCourse(courseId3, &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Mathematics&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;021.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;obj.deleteCourse(courseId2);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;022.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;obj.listCourse();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;023.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;024.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;025.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Long  saveCourse(String courseName)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;026.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;027.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Session session =  HibernateUtil.getSessionFactory().openSession();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;028.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Transaction transaction = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;null&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;029.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Long courseId = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;null&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;030.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;try&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;031.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction =  session.beginTransaction();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;032.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Course course  = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;new&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Course();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;033.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;course.setCourseName(courseName);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;034.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;courseId =  (Long) session.save(course);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;035.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction.commit();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;036.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;catch&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;(HibernateException e) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;037.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction.rollback();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;038.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;e.printStackTrace();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;039.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;finally&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;040.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;session.close();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;041.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;042.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;courseId;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;043.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;044.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;045.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;void&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;listCourse()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;046.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;047.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Session session =  HibernateUtil.getSessionFactory().openSession();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;048.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Transaction transaction = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;null&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;049.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;try&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;050.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction =  session.beginTransaction();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;051.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;List courses =  session.createQuery(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;from Course&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;).list();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;052.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;for&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;(Iterator iterator = courses.iterator();  iterator.hasNext();)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;053.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;054.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;                &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 128px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Course course = (Course) iterator.next();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;055.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;                &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 128px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;System.out.println(course.getCourseName());&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;056.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;057.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction.commit();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;058.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;catch&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;(HibernateException e) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;059.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction.rollback();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;060.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;e.printStackTrace();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;061.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;finally&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;062.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;session.close();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;063.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;064.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;065.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;066.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;void&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;updateCourse(Long courseId, String courseName)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;067.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;068.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Session session =  HibernateUtil.getSessionFactory().openSession();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;069.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Transaction transaction = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;null&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;070.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;try&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;071.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction =  session.beginTransaction();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;072.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Course course  = (Course) session.get(Course.&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;class&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, courseId);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;073.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;course.setCourseName(courseName);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;074.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction.commit();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;075.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;catch&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;(HibernateException e) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;076.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction.rollback();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;077.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;e.printStackTrace();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;078.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;finally&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;079.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;session.close();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;080.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;081.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;082.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;083.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;void&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;deleteCourse(Long courseId)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;084.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;085.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Session session =  HibernateUtil.getSessionFactory().openSession();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;086.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Transaction transaction = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;null&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;087.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;try&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;088.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction =  session.beginTransaction();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;089.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Course course  = (Course) session.get(Course.&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;class&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, courseId);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line  alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;090.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;session.delete(course);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;091.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction.commit();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;092.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;catch&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;(HibernateException e) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;093.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;transaction.rollback();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;094.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;e.printStackTrace();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;095.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;} &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;finally&lt;/code&gt;  &lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;096.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;            &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 96px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;session.close();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;097.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;        &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 64px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;098.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;099.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
The first call to the &lt;i&gt;openSession()&lt;/i&gt; method begins the  session. The &lt;i&gt;session.beginTransaction() &lt;/i&gt;method is used to start  a new transaction. Here we have four different methods to perform the  CRUD operations. &lt;br /&gt;
The &lt;i&gt;saveCourse()&lt;/i&gt; method is used to save a new &lt;i&gt;Course&lt;/i&gt;  object to the database.  In the &lt;i&gt;saveCourse()&lt;/i&gt;method a new  object of the &lt;i&gt;Course&lt;/i&gt; class is created and the &lt;i&gt;courseName&lt;/i&gt;  value is set, the &lt;i&gt;courseId&lt;/i&gt; value is auto generated so the  value needn&#39;t be set here. The&lt;i&gt; session.save()&lt;/i&gt; method is used to  persist the value in the database and once the value is saved,  the id  value (Primary key) is returned. Here the &lt;i&gt;courseId&lt;/i&gt; value is of  type &lt;i&gt;long&lt;/i&gt; so we typecast the returned value to &lt;i&gt;Long&lt;/i&gt;.  Once the object is saved, the transaction is committed. If any exception  occurs then the transaction is rolledback. The transaction ends either  through commit or rollback action. Once the transaction ends the session  is closed.&lt;br /&gt;
The &lt;i&gt;listCourse()&lt;/i&gt; method is used to list all the courses. The  &lt;i&gt;session.createQuery()&lt;/i&gt; method is used to create a query object  which helps in retrieving the persistant objects. Here we use Hibernate  Query Language (HQL). &quot;&lt;i&gt;from Course&lt;/i&gt;&quot; returns a list of all the  courses in the COURSES table. Note that in the HQL we only specify the  java class names and not the table names. Later, using the for loop we  iterate the list of courses and display them on the console.&lt;br /&gt;
The &lt;i&gt;updateCourse()&lt;/i&gt; method is used to update the course name.  It takes &lt;i&gt;the courseId&lt;/i&gt; and the new &lt;i&gt;courseName&lt;/i&gt; as input  parameters. The &lt;i&gt;courseId&lt;/i&gt; is used to retrive the actual course  object using the &lt;i&gt;session.get()&lt;/i&gt; method. The&lt;i&gt; session.get()&lt;/i&gt;  method takes the class name and the id value as the input parameter and  returns the corresponding Object. Here we set the new course name to  the &lt;i&gt;Course&lt;/i&gt; object and commit the transaction. We need not  explicitly call the &lt;i&gt;session.save() &lt;/i&gt;method to persist the  object. Hibernate will automatically update the database when  the state  of the persistant object is modified inside a transaction. This feature  of Hibernate is called &lt;i&gt;automatic dirty checking&lt;/i&gt;.&lt;br /&gt;
The &lt;i&gt;deleteCourse()&lt;/i&gt; method is used to delete a &lt;i&gt;Course&lt;/i&gt;  object. This method is similar to the &lt;i&gt;updateCourse()&lt;/i&gt; method,  here instead of updating the object we call the &lt;i&gt;session.delete()&lt;/i&gt;  method to delete a persistant object.&lt;br /&gt;
The figure below shows the final directory structure of the example.&lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-18.gif&quot; /&gt; &lt;br /&gt;
To run the example, first start the HSQLDB server. To start the HSQLDB  server, run the command prompt, go to the hsqldb directory and execute  the following command. &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_80911&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;1.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;java -cp ./lib/hsqldb.jar  org.hsqldb.Server&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-13.gif&quot; /&gt; &lt;br /&gt;
After starting the server, run the &lt;i&gt;Main&lt;/i&gt; class. On startup the  database schema will be created and the following actions will happen. &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_877546&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;01.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;static&lt;/code&gt;  &lt;code class=&quot;keyword&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;main(String[]  args) {&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;02.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Main obj = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;new&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;Main();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;03.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Long courseId1 = obj.saveCourse(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Physics&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;04.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Long courseId2 = obj.saveCourse(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Chemistry&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;05.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Long courseId3 = obj.saveCourse(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Maths&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;06.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;obj.listCourse();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;07.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;obj.updateCourse(courseId3, &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Mathematics&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;08.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;obj.deleteCourse(courseId2);&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;09.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;    &lt;/code&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 32px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;obj.listCourse();&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;10.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
Each time on startup the database schema will be droped and  recreated, if you want to use the existing one change the value of &lt;i&gt;hbm2ddl.auto&lt;/i&gt;  option to update. &lt;br /&gt;
The SQL statement generated  gets displayed on the console. This is  set using the&lt;i&gt; show_sql &lt;/i&gt;option in the hibernate configuration  file.                                                        &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_143569&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;01.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate: insert into COURSES  (COURSE_ID, COURSE_NAME) values (null, ?)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;02.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  call identity()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;03.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  insert into COURSES (COURSE_ID, COURSE_NAME) values (null, ?)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;04.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  call identity()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;05.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  insert into COURSES (COURSE_ID, COURSE_NAME) values (null, ?)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;06.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  call identity()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;07.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  select course0_.COURSE_ID as COURSE1_0_, course0_.COURSE_NAME as  COURSE2_0_ from COURSES course0_&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;08.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Physics&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;09.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Chemistry&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;10.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Maths&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;11.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  select course0_.COURSE_ID as COURSE1_0_0_, course0_.COURSE_NAME as  COURSE2_0_0_ from COURSES course0_ where course0_.COURSE_ID=?&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;12.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  update COURSES set COURSE_NAME=? where COURSE_ID=?&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;13.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  select course0_.COURSE_ID as COURSE1_0_0_, course0_.COURSE_NAME as  COURSE2_0_0_ from COURSES course0_ where course0_.COURSE_ID=?&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;14.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  delete from COURSES where COURSE_ID=?&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;15.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Hibernate:  select course0_.COURSE_ID as COURSE1_0_, course0_.COURSE_NAME as  COURSE2_0_ from COURSES course0_&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;code class=&quot;number&quot;&gt;16.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Physics&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;17.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;Mathematics&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
Now let&#39;s check whether the database schema is created and the data is  inserted into the &lt;i&gt;COURSES&lt;/i&gt; table or not. Open a new command  prompt, go to the hsqldb installed directory and type the following  command.                                                        &lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter &quot; id=&quot;highlighter_838873&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;code class=&quot;number&quot;&gt;1.&lt;/code&gt;&lt;span class=&quot;content&quot;&gt;&lt;span class=&quot;block&quot; style=&quot;margin-left: 0px !important;&quot;&gt;&lt;code class=&quot;plain&quot;&gt;java -cp ./lib/hsqldb.jar  org.hsqldb.util.DatabaseManager&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-14.gif&quot; /&gt; &lt;br /&gt;
The following dialog box pops up. Select the Type as &quot;&lt;i&gt;HSQL Database  Engine Server&lt;/i&gt;&quot; and click &lt;i&gt;Ok&lt;/i&gt;.                                                         &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-15.gif&quot; /&gt; &lt;br /&gt;
The HSQL Databse Manager window opens. Here you can enter the following  SQL statement, and see the data is successfully stored in the &lt;i&gt;COURSES&lt;/i&gt;  table.                                                        &lt;br /&gt;
&lt;img src=&quot;http://vaannila.com/images/hibernate/hibernate-example-pic-19.gif&quot; /&gt; &lt;br /&gt;
To shutdown the HSQLDB properly enter &quot;&lt;i&gt;shutdown&lt;/i&gt;&quot; and click the &lt;i&gt;Execute&lt;/i&gt;  button. Alternatively you can also shutdown programmatically by closing  the SessionFactory, using &lt;i&gt;HibernateUtil.getSessionFactory().close()&lt;/i&gt;  method.&lt;/div&gt;
&lt;g:plusone size=&quot;medium&quot;&gt;&lt;/g:plusone&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6775105882860234755/posts/default/963214025235658236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6775105882860234755/posts/default/963214025235658236'/><link rel='alternate' type='text/html' href='http://hibernate4u.blogspot.com/2010/07/blog-post.html' title='Hiber nate Tools Introduction:'/><author><name>Chandra</name><uri>http://www.blogger.com/profile/01209478501446255220</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry></feed>