<?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: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-6615883157507452442</id><updated>2012-01-04T09:41:31.726-08:00</updated><category term='linux'/><category term='rmdir'/><category term='commands'/><category term='cp'/><category term='hibernate tutorial examples'/><category term='rm'/><category term='wc'/><category term='SCJP 1.5 Mocks'/><category term='cd'/><category term='cat'/><category term='la'/><category term='ls'/><category term='mkdir'/><category term='pwd'/><title type='text'>Ananth</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-4396856347117049940</id><published>2008-11-06T23:04:00.000-08:00</published><updated>2008-11-06T23:05:08.779-08:00</updated><title type='text'>Run MySQL in Windows</title><content type='html'>Step 1: Open Command Prompt&lt;br /&gt;        C:\Program Files\MySQL\MySQL Server 5.0\bin&gt;mysql -uroot -p&lt;br /&gt;&lt;br /&gt;Step 2:&lt;br /&gt;mysql&gt; show databases;&lt;br /&gt;+--------------------+&lt;br /&gt;| Database           |&lt;br /&gt;+--------------------+&lt;br /&gt;| information_schema |&lt;br /&gt; | hibernatetutorial  |&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;The above command shows all the existing databases.&lt;br /&gt;&lt;br /&gt;Step 3:&lt;br /&gt;       Create new MySQL user&lt;br /&gt;       CREATE USER 'sark'@'localhost' IDENTIFIED BY 'sark';&lt;br /&gt;&lt;br /&gt;Step 4:&lt;br /&gt;       Grant Permissions.&lt;br /&gt;      GRANT ALL PRIVILEGES ON *.* TO 'sark'@'localhost' IDENTIFIED BY 'sark' WITH GRANT OPTION;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 5:&lt;br /&gt;      To check the existing users.&lt;br /&gt;      mysql&gt; select User,Host from mysql.user;&lt;br /&gt;+-----------+--------------+&lt;br /&gt;| User      | Host         |&lt;br /&gt;+-----------+--------------+&lt;br /&gt;| root      | %            |&lt;br /&gt;| sark      | localhost    |&lt;br /&gt;+-----------+--------------+&lt;br /&gt;&lt;br /&gt;Step 6: To check the Permissions/privileges.&lt;br /&gt;&lt;br /&gt;mysql&gt; show grants for sark@localhost;&lt;br /&gt;+-------------------------------------------------------------------------------&lt;br /&gt;-------------------------------------------------------+&lt;br /&gt;| Grants for sark@localhost&lt;br /&gt;                                                       |&lt;br /&gt;+-------------------------------------------------------------------------------&lt;br /&gt;-------------------------------------------------------+&lt;br /&gt;| GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'sark'@'localhost' IDENTIFIED B&lt;br /&gt;Y PASSWORD '*A231ED0CF53E6EF33A1A79930EB2A82DB89812F2' |&lt;br /&gt;+-------------------------------------------------------------------------------&lt;br /&gt;-------------------------------------------------------+&lt;br /&gt;&lt;br /&gt;Step 6:&lt;br /&gt;       Exit from root user and login as 'sark' user;&lt;br /&gt;&lt;br /&gt;     mysql&gt; exit;&lt;br /&gt;     Bye&lt;br /&gt;&lt;br /&gt;   C:\Program Files\MySQL\MySQL Server 5.0\bin&gt;mysql -usark -psark&lt;br /&gt;   Welcome to the MySQL monitor.  Commands end with ; or \g.&lt;br /&gt;   Your MySQL connection id is 43 to server version: 5.0.24-community-nt&lt;br /&gt;&lt;br /&gt;   Type 'help;' or '\h' for help. Type '\c' to clear the buffer.&lt;br /&gt;&lt;br /&gt;   mysql&gt;&lt;br /&gt;&lt;br /&gt;Step 7:&lt;br /&gt;     Create database 'sarkDB'&lt;br /&gt;     mysql&gt; CREATE DATABASE sarkDB;&lt;br /&gt;&lt;br /&gt;Step 8:&lt;br /&gt;      Use Database&lt;br /&gt;     mysql&gt; use sarkDB;&lt;br /&gt;     Database changed&lt;br /&gt;&lt;br /&gt;Step 9:&lt;br /&gt;      Create table demo_people.&lt;br /&gt;     mysql&gt;  CREATE TABLE `demo_people` (&lt;br /&gt;       `pid` int(11) NOT NULL,&lt;br /&gt;      `name` varchar(20) default NULL,&lt;br /&gt;       `phone` int(11) default NULL,&lt;br /&gt;      PRIMARY KEY  (`pid`)&lt;br /&gt;     );&lt;br /&gt;Query OK, 0 rows affected (0.23 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-4396856347117049940?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/4396856347117049940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=4396856347117049940' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4396856347117049940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4396856347117049940'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2008/11/run-mysql-in-windows.html' title='Run MySQL in Windows'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-4486991296197959321</id><published>2008-07-06T22:15:00.000-07:00</published><updated>2008-07-06T23:31:01.893-07:00</updated><title type='text'>AJAX Introduction</title><content type='html'>&lt;span style="font-weight:bold;"&gt;AJAX = Asynchronous JavaScript and XML&lt;/span&gt;&lt;br /&gt;AJAX is not a new programming language, but a technique for creating better, faster, and more interactive web applications.&lt;br /&gt;&lt;br /&gt;With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can trade data with a web server, without reloading the page.&lt;br /&gt;&lt;br /&gt;AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages.&lt;br /&gt;  &lt;br /&gt;The AJAX technique makes Internet applications smaller, faster and more user-friendly.&lt;br /&gt;&lt;br /&gt;  AJAX is a browser technology independent of web server software. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;AJAX is Based on Web Standards&lt;/span&gt;&lt;br /&gt;AJAX is based on the following web standards:&lt;br /&gt;&lt;br /&gt;JavaScript &lt;br /&gt;XML &lt;br /&gt;HTML &lt;br /&gt;CSS &lt;br /&gt;The web standards used in AJAX are well defined, and supported by all major browsers. AJAX applications are browser and platform independent.&lt;br /&gt;&lt;br /&gt;AJAX is About Better Internet Applications&lt;br /&gt;Web applications have many benefits over desktop applications; they can reach a larger audience, they are easier to install and support, and easier to develop.&lt;br /&gt;&lt;br /&gt;However, Internet applications are not always as "rich" and user-friendly as traditional desktop applications. &lt;br /&gt;&lt;br /&gt;With AJAX, Internet applications can be made richer and more user-friendly.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;AJAX Uses HTTP Requests&lt;/span&gt;&lt;br /&gt;In traditional JavaScript coding, if you want to get any information from a database or a file on the server, or send user information to a server, you will have to make an HTML form and GET or POST data to the server. The user will have to click the "Submit" button to send/get the information, wait for the server to respond, then a new page will load with the results.&lt;br /&gt;&lt;br /&gt;Because the server returns a new page each time the user submits input, traditional web applications can run slowly and tend to be less user-friendly.&lt;br /&gt;&lt;br /&gt;With AJAX, your JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object&lt;br /&gt;&lt;br /&gt;With an HTTP request, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;The XMLHttpRequest Object&lt;/span&gt;&lt;br /&gt;By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded!&lt;br /&gt;&lt;br /&gt;AJAX was made popular in 2005 by Google (with Google Suggest).&lt;br /&gt;&lt;br /&gt;Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions.&lt;br /&gt;&lt;br /&gt;The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Opera 8+, and Netscape 7.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Your First AJAX Application&lt;/span&gt;&lt;br /&gt;To understand how AJAX works, we will create a small AJAX application.&lt;br /&gt;&lt;br /&gt;First, we are going to create a standard HTML form with two text fields: username and time. The username field will be filled in by the user and the time field will be filled in using AJAX.&lt;br /&gt;&lt;br /&gt;The HTML file will be named "testAjax.htm", and it looks like this (notice that the HTML form below has no submit button!):&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;body&gt;&lt;form name="myForm"&gt;&lt;br /&gt;Name: &lt;input type="text" name="username" /&gt;&lt;br /&gt;Time: &lt;input type="text" name="time" /&gt;&lt;br /&gt;&lt;/form&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;AJAX - Browser Support&lt;/span&gt;&lt;br /&gt;The keystone of AJAX is the XMLHttpRequest object.&lt;br /&gt;&lt;br /&gt;Different browsers use different methods to create the XMLHttpRequest object.&lt;br /&gt;&lt;br /&gt;Internet Explorer uses an ActiveXObject, while other browsers uses the built-in JavaScript object called XMLHttpRequest.&lt;br /&gt;&lt;br /&gt;To create this object, and deal with different browsers, we are going to use a "try and catch" statement. You can read more about the try and catch statement in our JavaScript tutorial.&lt;br /&gt;&lt;br /&gt;Let's update our "testAjax.htm" file with the JavaScript that creates the XMLHttpRequest object:&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;body&gt;&lt;script type="text/javascript"&gt;function ajaxFunction()&lt;br /&gt;{var xmlHttp;&lt;br /&gt;try&lt;br /&gt;  {  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }&lt;br /&gt;catch (e)&lt;br /&gt;  {  // Internet Explorer  try&lt;br /&gt;    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }&lt;br /&gt;  catch (e)&lt;br /&gt;    {    try&lt;br /&gt;      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }&lt;br /&gt;    catch (e)&lt;br /&gt;      {      alert("Your browser does not support AJAX!");      return false;      }    }  }  }&lt;/script&gt;&lt;form name="myForm"&gt;&lt;br /&gt;Name: &lt;input type="text" name="username" /&gt;&lt;br /&gt;Time: &lt;input type="text" name="time" /&gt;&lt;br /&gt;&lt;/form&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;br /&gt;Example explained: First create a variable xmlHttp to hold the XMLHttpRequest object.&lt;br /&gt;&lt;br /&gt;Then try to create the object with XMLHttp=new XMLHttpRequest(). This is for the Firefox, Opera, and Safari browsers. If that fails, try xmlHttp=new ActiveXObject("Msxml2.XMLHTTP") which is for Internet Explorer 6.0+, if that also fails, try xmlHttp=new ActiveXObject("Microsoft.XMLHTTP") which is for Internet Explorer 5.5+&lt;br /&gt;&lt;br /&gt;If none of the three methods work, the user has a very outdated browser, and he or she will get an alert stating that the browser doesn't support AJAX.&lt;br /&gt;&lt;br /&gt;Note: The browser-specific code above is long and quite complex. However, this is the code you can use every time you need to create an XMLHttpRequest object, so you can just copy and paste it whenever you need it. The code above is compatible with all the popular browsers: Internet Explorer, Opera, Firefox, and Safari.&lt;br /&gt;&lt;br /&gt;The next chapter shows how to use the XMLHttpRequest object to communicate with the server.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;AJAX - More About the XMLHttpRequest Object&lt;/span&gt;&lt;br /&gt;Before sending data to the server, we have to explain three important properties of the XMLHttpRequest object.&lt;br /&gt;&lt;br /&gt;The onreadystatechange Property&lt;br /&gt;After a request to the server, we need a function that can receive the data that is returned by the server.&lt;br /&gt;&lt;br /&gt;The onreadystatechange property stores the function that will process the response from a server. The following code defines an empty function and sets the onreadystatechange property at the same time:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;The readyState Property&lt;/span&gt;&lt;br /&gt;The readyState property holds the status of the server's response. Each time the readyState changes, the onreadystatechange function will be executed.&lt;br /&gt;&lt;br /&gt;Here are the possible values for the readyState property:&lt;br /&gt;State      Description &lt;br /&gt; 0     The request is not initialized &lt;br /&gt; 1     The request has been set up &lt;br /&gt; 2     The request has been sent &lt;br /&gt; 3     The request is in process &lt;br /&gt; 4     The request is complete &lt;br /&gt;&lt;br /&gt;We are going to add an If statement to the onreadystatechange function to test if our response is complete (this means that we can get our data):&lt;br /&gt;&lt;br /&gt;xmlHttp.onreadystatechange=function()&lt;br /&gt;{&lt;br /&gt;if(xmlHttp.readyState==4)&lt;br /&gt;  {&lt;br /&gt;  // Get the data from the server's response&lt;br /&gt;  }&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;The responseText Property&lt;br /&gt;The data sent back from the server can be retrieved with the responseText property.&lt;br /&gt;&lt;br /&gt;In our code, we will set the value of our "time" input field equal to responseText:&lt;br /&gt;&lt;br /&gt;xmlHttp.onreadystatechange=function()&lt;br /&gt;{&lt;br /&gt;if(xmlHttp.readyState==4)&lt;br /&gt;  {&lt;br /&gt;  document.myForm.time.value=xmlHttp.responseText;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;span style="font-weight:bold;"&gt;AJAX - Sending a Request to the Server&lt;/span&gt;&lt;br /&gt;To send off a request to the server, we use the open() method and the send() method.&lt;br /&gt;&lt;br /&gt;The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously. The send() method sends the request off to the server. If we assume that the HTML and ASP file are in the same directory, the code would be: &lt;br /&gt;&lt;br /&gt;xmlHttp.open("GET","time.asp",true);&lt;br /&gt;xmlHttp.send(null); &lt;br /&gt;&lt;br /&gt;Now we must decide when the AJAX function should be executed. We will let the function run "behind the scenes" when the user types something in the username text field:&lt;br /&gt;&lt;br /&gt;&lt;form name="myForm"&gt;&lt;br /&gt;Name: &lt;input type="text"&lt;br /&gt;onkeyup="ajaxFunction();" name="username" /&gt;&lt;br /&gt;Time: &lt;input type="text" name="time" /&gt;&lt;br /&gt;&lt;/form&gt; &lt;br /&gt;&lt;br /&gt;Our updated AJAX-ready "testAjax.htm" file now looks like this:&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;body&gt;&lt;script type="text/javascript"&gt;function ajaxFunction()&lt;br /&gt;{var xmlHttp;&lt;br /&gt;try&lt;br /&gt;  {  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }&lt;br /&gt;catch (e)&lt;br /&gt;  {  // Internet Explorer  try&lt;br /&gt;    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }&lt;br /&gt;  catch (e)&lt;br /&gt;    {    try&lt;br /&gt;      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }&lt;br /&gt;    catch (e)&lt;br /&gt;      {      alert("Your browser does not support AJAX!");      return false;      }    }  }&lt;br /&gt;  xmlHttp.onreadystatechange=function()&lt;br /&gt;    {&lt;br /&gt;    if(xmlHttp.readyState==4)&lt;br /&gt;      {&lt;br /&gt;      document.myForm.time.value=xmlHttp.responseText;&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  xmlHttp.open("GET","time.asp",true);&lt;br /&gt;  xmlHttp.send(null);  }&lt;/script&gt;&lt;form name="myForm"&gt;&lt;br /&gt;Name: &lt;input type="text"&lt;br /&gt;onkeyup="ajaxFunction();" name="username" /&gt;&lt;br /&gt;Time: &lt;input type="text" name="time" /&gt;&lt;br /&gt;&lt;/form&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;AJAX - The Server-Side ASP Script&lt;/span&gt;&lt;br /&gt;Now we are going to create the script that displays the current server time.&lt;br /&gt;&lt;br /&gt;The responseText property (explained in the previous chapter) will store the data returned from the server. Here we want to send back the current time. The code in "time.asp" looks like this:&lt;br /&gt;&lt;br /&gt;&lt;%&lt;br /&gt;response.expires=-1&lt;br /&gt;response.write(time)&lt;br /&gt;%&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Note&lt;/span&gt;: The Expires property sets how long (in minutes) a page will be cached on a browser before it expires. If a user returns to the same page before it expires, the cached version is displayed. Response.Expires=-1 indicates that the page will never be cached.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-4486991296197959321?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/4486991296197959321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=4486991296197959321' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4486991296197959321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4486991296197959321'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2008/07/ajax-introduction.html' title='AJAX Introduction'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-8339913662029746360</id><published>2008-01-21T22:38:00.000-08:00</published><updated>2008-01-21T22:40:21.054-08:00</updated><title type='text'>MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN</title><content type='html'>First, some sample data:&lt;br /&gt;Mr Brown, Person number 1, has a phone number 01225 708225&lt;br /&gt;Miss Smith, Person number 2, has a phone number 01225 899360&lt;br /&gt;Mr Pullen, Person number 3, has a phone number 01380 724040&lt;br /&gt;and also:&lt;br /&gt;Person number 1 is selling property number 1 - Old House Farm&lt;br /&gt;Person number 3 is selling property number 2 - The Willows&lt;br /&gt;Person number 3 is (also) selling property number 3 - Tall Trees&lt;br /&gt;Person number 3 is (also) selling property number 4 - The Melksham Florist&lt;br /&gt;Person number 4 is selling property number 5 - Dun Roamin.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from demo_people;&lt;br /&gt;+------------+--------------+------+&lt;br /&gt;| name       | phone        | pid  |&lt;br /&gt;+------------+--------------+------+&lt;br /&gt;| Mr Brown   | 01225 708225 |    1 |&lt;br /&gt;| Miss Smith | 01225 899360 |    2 |&lt;br /&gt;| Mr Pullen  | 01380 724040 |    3 |&lt;br /&gt;+------------+--------------+------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from demo_property;&lt;br /&gt;+------+------+----------------------+&lt;br /&gt;| pid  | spid | selling              |&lt;br /&gt;+------+------+----------------------+&lt;br /&gt;|    1 |    1 | Old House Farm       |&lt;br /&gt;|    3 |    2 | The Willows          |&lt;br /&gt;|    3 |    3 | Tall Trees           |&lt;br /&gt;|    3 |    4 | The Melksham Florist |&lt;br /&gt;|    4 |    5 | Dun Roamin           |&lt;br /&gt;+------+------+----------------------+&lt;br /&gt;5 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If I do a regular JOIN (with none of the keywords INNER, OUTER, LEFT or RIGHT), then I get all records that match in the appropriate way in the two tables, and records in both incoming tables that do not match are not reported:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt; select name, phone, selling &lt;br /&gt;from demo_people join demo_property &lt;br /&gt;on demo_people.pid = demo_property.pid;&lt;br /&gt;+-----------+--------------+----------------------+&lt;br /&gt;| name      | phone        | selling              |&lt;br /&gt;+-----------+--------------+----------------------+&lt;br /&gt;| Mr Brown  | 01225 708225 | Old House Farm       |&lt;br /&gt;| Mr Pullen | 01380 724040 | The Willows          |&lt;br /&gt;| Mr Pullen | 01380 724040 | Tall Trees           |&lt;br /&gt;| Mr Pullen | 01380 724040 | The Melksham Florist |&lt;br /&gt;+-----------+--------------+----------------------+&lt;br /&gt;4 rows in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If I do a LEFT JOIN, I get all records that match in the same way and IN ADDITION I get an extra record for each unmatched record in the left table of the join - thus ensuring (in my example) that every PERSON gets a mention:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt; select name, phone, selling &lt;br /&gt;from demo_people left join demo_property &lt;br /&gt;on demo_people.pid = demo_property.pid; &lt;br /&gt;+------------+--------------+----------------------+&lt;br /&gt;| name       | phone        | selling              |&lt;br /&gt;+------------+--------------+----------------------+&lt;br /&gt;| Mr Brown   | 01225 708225 | Old House Farm       |&lt;br /&gt;| Miss Smith | 01225 899360 | NULL                 |&lt;br /&gt;| Mr Pullen  | 01380 724040 | The Willows          |&lt;br /&gt;| Mr Pullen  | 01380 724040 | Tall Trees           |&lt;br /&gt;| Mr Pullen  | 01380 724040 | The Melksham Florist |&lt;br /&gt;+------------+--------------+----------------------+&lt;br /&gt;5 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If I do a RIGHT JOIN, I get all the records that match and IN ADDITION I get an extra record for each unmatched record in the right table of the join - im my example, that means that each property gets a mention even if we don't have seller details:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt; select name, phone, selling &lt;br /&gt;from demo_people right join demo_property &lt;br /&gt;on demo_people.pid = demo_property.pid;&lt;br /&gt;+-----------+--------------+----------------------+&lt;br /&gt;| name      | phone        | selling              |&lt;br /&gt;+-----------+--------------+----------------------+&lt;br /&gt;| Mr Brown  | 01225 708225 | Old House Farm       |&lt;br /&gt;| Mr Pullen | 01380 724040 | The Willows          |&lt;br /&gt;| Mr Pullen | 01380 724040 | Tall Trees           |&lt;br /&gt;| Mr Pullen | 01380 724040 | The Melksham Florist |&lt;br /&gt;| NULL      | NULL         | Dun Roamin           |&lt;br /&gt;+-----------+--------------+----------------------+&lt;br /&gt;5 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;An INNER JOIN does a full join, just like the first example, and the word OUTER may be added after the word LEFT or RIGHT in the last two examples - it's provided for ODBC compatability and doesn't add an extra capabilities.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-8339913662029746360?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/8339913662029746360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=8339913662029746360' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/8339913662029746360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/8339913662029746360'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2008/01/mysql-left-join-and-right-join-inner.html' title='MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-7319347368637160174</id><published>2008-01-01T21:00:00.000-08:00</published><updated>2008-01-01T21:29:30.568-08:00</updated><title type='text'>Java API for XML Processing</title><content type='html'>The Java API for XML Processing (JAXP) is for processing XML data using applications written in the Java programming language. JAXP leverages the parser standards Simple API for XML Parsing (SAX) and Document Object Model (DOM) so that you can choose to parse your data as a stream of events or to build an object representation of it. JAXP also supports the Extensible Stylesheet Language Transformations (XSLT) standard, giving you control over the presentation of the data and enabling you to convert the data to other XML documents or to other formats, such as HTML. JAXP also provides namespace support, allowing you to work with DTDs that might otherwise have naming conflicts. &lt;br /&gt;&lt;br /&gt;Designed to be flexible, JAXP allows you to use any XML-compliant parser from within your application. It does this with what is called a pluggability layer, which lets you plug in an implementation of the SAX or DOM API. The pluggability layer also allows you to plug in an XSL processor, letting you control how your XML data is displayed. &lt;br /&gt;&lt;br /&gt;The basic outline of the SAX parsing APIs are shown in Figure 4-1. To start the process, an instance of the SAXParserFactory class is used to generate an instance of the parser. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The main JAXP APIs are defined in the javax.xml.parsers package. That package contains vendor-neutral factory classes--SAXParserFactory, DocumentBuilderFactory, and TransformerFactory--which give you a SAXParser, a DocumentBuilder, and an XSLT transformer, respectively. DocumentBuilder, in turn, creates a DOM-compliant Document object. &lt;br /&gt;&lt;br /&gt;The factory APIs let you plug in an XML implementation offered by another vendor without changing your source code. The implementation you get depends on the setting of the javax.xml.parsers.SAXParserFactory, javax.xml.parsers.DocumentBuilderFactory, and javax.xml.transform.TransformerFactory system properties, using System.setProperties() in the code, &lt;sysproperty key="..." value="..."/&gt; in an Ant build script, or -DpropertyName="..." on the command line. The default values (unless overridden at runtime on the command line or in the code) point to Sun's implementation. &lt;br /&gt;&lt;br /&gt;The SAX and DOM APIs are defined by the XML-DEV group and by the W3C, respectively. The libraries that define those APIs are as follows: &lt;br /&gt;&lt;br /&gt;javax.xml.parsers: The JAXP APIs, which provide a common interface for different vendors' SAX and DOM parsers&lt;br /&gt;org.w3c.dom: Defines the Document class (a DOM) as well as classes for all the components of a DOM&lt;br /&gt;org.xml.sax: Defines the basic SAX APIs&lt;br /&gt;javax.xml.transform: Defines the XSLT APIs that let you transform XML into other forms&lt;br /&gt;The Simple API for XML (SAX) is the event-driven, serial-access mechanism that does element-by-element processing. The API for this level reads and writes XML to a data repository or the web. For server-side and high-performance applications, you will want to fully understand this level. But for many applications, a minimal understanding will suffice. &lt;br /&gt;&lt;br /&gt;The DOM API is generally an easier API to use. It provides a familiar tree structure of objects. You can use the DOM API to manipulate the hierarchy of application objects it encapsulates. The DOM API is ideal for interactive applications because the entire object model is present in memory, where it can be accessed and manipulated by the user. &lt;br /&gt;&lt;br /&gt;On the other hand, constructing the DOM requires reading the entire XML structure and holding the object tree in memory, so it is much more CPU- and memory-intensive. For that reason, the SAX API tends to be preferred for server-side applications and data filters that do not require an in-memory representation of the data. &lt;br /&gt;&lt;br /&gt;Finally, the XSLT APIs defined in javax.xml.transform let you write XML data to a file or convert it into other forms. And, as you'll see in the XSLT section of this tutorial, you can even use it in conjunction with the SAX APIs to convert legacy data to XML. &lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_h8w_fktOw40/R3scj3QMhkI/AAAAAAAAAAw/GQjK5enjJE4/s1600-h/jaxpintro-saxApi.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp0.blogger.com/_h8w_fktOw40/R3scj3QMhkI/AAAAAAAAAAw/GQjK5enjJE4/s200/jaxpintro-saxApi.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5150742001281173058" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The parser wraps a SAXReader object. When the parser's parse() method is invoked, the reader invokes one of several callback methods implemented in the application. Those methods are defined by the interfaces ContentHandler, ErrorHandler, DTDHandler, and EntityResolver. &lt;br /&gt;&lt;br /&gt;Here is a summary of the key SAX APIs: &lt;br /&gt;&lt;br /&gt;SAXParserFactory &lt;br /&gt;&lt;br /&gt;A SAXParserFactory object creates an instance of the parser determined by the system property, javax.xml.parsers.SAXParserFactory. &lt;br /&gt;&lt;br /&gt;SAXParser &lt;br /&gt;&lt;br /&gt;The SAXParser interface defines several kinds of parse() methods. In general, you pass an XML data source and a DefaultHandler object to the parser, which processes the XML and invokes the appropriate methods in the handler object. &lt;br /&gt;&lt;br /&gt;SAXReader &lt;br /&gt;&lt;br /&gt;The SAXParser wraps a SAXReader. Typically, you don't care about that, but every once in a while you need to get hold of it using SAXParser's getXMLReader() so that you can configure it. It is the SAXReader that carries on the conversation with the SAX event handlers you define. &lt;br /&gt;&lt;br /&gt;DefaultHandler &lt;br /&gt;&lt;br /&gt;Not shown in the diagram, a DefaultHandler implements the ContentHandler, ErrorHandler, DTDHandler, and EntityResolver interfaces (with null methods), so you can override only the ones you're interested in. &lt;br /&gt;&lt;br /&gt;ContentHandler &lt;br /&gt;&lt;br /&gt;Methods such as startDocument, endDocument, startElement, and endElement are invoked when an XML tag is recognized. This interface also defines the methods characters and processingInstruction, which are invoked when the parser encounters the text in an XML element or an inline processing instruction, respectively. &lt;br /&gt;&lt;br /&gt;ErrorHandler &lt;br /&gt;&lt;br /&gt;Methods error, fatalError, and warning are invoked in response to various parsing errors. The default error handler throws an exception for fatal errors and ignores other errors (including validation errors). That's one reason you need to know something about the SAX parser, even if you are using the DOM. Sometimes, the application may be able to recover from a validation error. Other times, it may need to generate an exception. To ensure the correct handling, you'll need to supply your own error handler to the parser. &lt;br /&gt;&lt;br /&gt;DTDHandler &lt;br /&gt;&lt;br /&gt;Defines methods you will generally never be called upon to use. Used when processing a DTD to recognize and act on declarations for an unparsed entity. &lt;br /&gt;&lt;br /&gt;EntityResolver &lt;br /&gt;&lt;br /&gt;The resolveEntity method is invoked when the parser must identify data identified by a URI. In most cases, a URI is simply a URL, which specifies the location of a document, but in some cases the document may be identified by a URN--a public identifier, or name, that is unique in the web space. The public identifier may be specified in addition to the URL. The EntityResolver can then use the public identifier instead of the URL to find the document--for example, to access a local copy of the document if one exists. &lt;br /&gt;&lt;br /&gt;A typical application implements most of the ContentHandler methods, at a minimum. Because the default implementations of the interfaces ignore all inputs except for fatal errors, a robust implementation may also want to implement the ErrorHandler methods. &lt;br /&gt;&lt;br /&gt;The SAX Packages &lt;br /&gt;The SAX parser is defined in the packages listed in Table 4-1.&lt;br /&gt;&lt;br /&gt;Table 4-1 SAX Packages  Package  Description  &lt;br /&gt;org.xml.sax  Defines the SAX interfaces. The name org.xml is the package prefix that was settled on by the group that defined the SAX API.  &lt;br /&gt;org.xml.sax.ext  Defines SAX extensions that are used for doing more sophisticated SAX processing--for example, to process a document type definition (DTD) or to see the detailed syntax for a file.  &lt;br /&gt;org.xml.sax.helpers  Contains helper classes that make it easier to use SAX--for example, by defining a default handler that has null methods for all the interfaces, so that you only need to override the ones you actually want to implement.  &lt;br /&gt;javax.xml.parsers  Defines the SAXParserFactory class, which returns the SAXParser. Also defines exception classes for reporting errors.  &lt;br /&gt;&lt;br /&gt;The Document Object Model APIs &lt;br /&gt;Figure 4-2 shows the DOM APIs in action. &lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_h8w_fktOw40/R3sdCHQMhlI/AAAAAAAAAA4/eiYShPSxdiE/s1600-h/jaxpintro-domApi.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_h8w_fktOw40/R3sdCHQMhlI/AAAAAAAAAA4/eiYShPSxdiE/s200/jaxpintro-domApi.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5150742520972215890" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You use the javax.xml.parsers.DocumentBuilderFactory class to get a DocumentBuilder instance, and you use that instance to produce a Document object that conforms to the DOM specification. The builder you get, in fact, is determined by the system property javax.xml.parsers.DocumentBuilderFactory, which selects the factory implementation that is used to produce the builder. (The platform's default value can be overridden from the command line.) &lt;br /&gt;&lt;br /&gt;You can also use the DocumentBuilder newDocument() method to create an empty Document that implements the org.w3c.dom.Document interface. Alternatively, you can use one of the builder's parse methods to create a Document from existing XML data. The result is a DOM tree like that shown in Figure 4-2. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Note: Although they are called objects, the entries in the DOM tree are actually fairly low-level data structures. For example, consider this structure: &lt;color&gt;blue&lt;/color&gt;. There is an element node for the color tag, and under that there is a text node that contains the data, blue! This issue will be explored at length in the DOM section of the tutorial, but developers who are expecting objects are usually surprised to find that invoking getNodeValue() on the element node returns nothing! For a truly object-oriented tree, see the JDOM API at http://www.jdom.org. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;The DOM Packages &lt;br /&gt;The Document Object Model implementation is defined in the packages listed in Table 4-2.&lt;br /&gt;&lt;br /&gt;Table 4-2 DOM Packages  Package  Description  &lt;br /&gt;org.w3c.dom  Defines the DOM programming interfaces for XML (and, optionally, HTML) documents, as specified by the W3C.  &lt;br /&gt;javax.xml.parsers  Defines the DocumentBuilderFactory class and the DocumentBuilder class, which returns an object that implements the W3C Document interface. The factory that is used to create the builder is determined by the javax.xml.parsers system property, which can be set from the command line or overridden when invoking the new Instance method. This package also defines the ParserConfigurationException class for reporting errors. &lt;br /&gt;&lt;br /&gt;The Extensible Stylesheet Language Transformations APIs &lt;br /&gt;Figure 4-3 shows the XSLT APIs in action. &lt;br /&gt;&lt;br /&gt;A TransformerFactory object is instantiated and used to create a Transformer. The source object is the input to the transformation process. A source object can be created from a SAX reader, from a DOM, or from an input stream. &lt;br /&gt;&lt;br /&gt;Similarly, the result object is the result of the transformation process. That object can be a SAX event handler, a DOM, or an output stream. &lt;br /&gt;&lt;br /&gt;When the transformer is created, it can be created from a set of transformation instructions, in which case the specified transformations are carried out. If it is created without any specific instructions, then the transformer object simply copies the source to the result. &lt;br /&gt;&lt;br /&gt;The XSLT Packages &lt;br /&gt;The XSLT APIs are defined in the packages shown in Table 4-3.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_h8w_fktOw40/R3sdWHQMhmI/AAAAAAAAABA/Jjo1pW-u5XI/s1600-h/jaxpintro-xsltApi.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_h8w_fktOw40/R3sdWHQMhmI/AAAAAAAAABA/Jjo1pW-u5XI/s200/jaxpintro-xsltApi.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5150742864569599586" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Table 4-3 XSLT Packages  Package  Description  &lt;br /&gt;javax.xml.transform  Defines the TransformerFactory and Transformer classes, which you use to get an object capable of doing transformations. After creating a transformer object, you invoke its transform() method, providing it with an input (source) and output (result).  &lt;br /&gt;javax.xml.transform.dom  Classes to create input (source) and output (result) objects from a DOM.  &lt;br /&gt;javax.xml.transform.sax  Classes to create input (source) objects from a SAX parser and output (result) objects from a SAX event handler.  &lt;br /&gt;javax.xml.transform.stream  Classes to create input (source) objects and output (result) objects from an I/O stream.  &lt;br /&gt;&lt;br /&gt;Simple API for XML (&lt;span style="font-weight:bold;"&gt;SAX&lt;/span&gt;), an event-driven, serial-access mechanism for accessing XML documents. This protocol is frequently used by servlets and network-oriented programs that need to transmit and receive XML documents, because it's the fastest and least memory-intensive mechanism that is currently available for dealing with XML documents, other than StAX. &lt;br /&gt;&lt;br /&gt;SAX is an event-driven model (you provide the callback methods, and the parser invokes them as it reads the XML data), and that makes it harder to visualize. Finally, you can't "back up" to an earlier part of the document, or rearrange it, any more than you can back up a serial data stream or rearrange characters you have read from that stream. &lt;br /&gt;&lt;br /&gt;For those reasons, developers who are writing a user-oriented application that displays an XML document and possibly modifies it will want to use the DOM mechanism &lt;br /&gt;&lt;br /&gt;even if you plan to build DOM applications exclusively, there are several important reasons for familiarizing yourself with the SAX model: &lt;br /&gt;&lt;br /&gt;Same Error Handling: The same kinds of exceptions are generated by the SAX and DOM APIs, so the error handling code is virtually identical.&lt;br /&gt;Handling Validation Errors: By default, the specifications require that validation errors (which you'll learn more about in this part of the tutorial) are ignored. If you want to throw an exception in the event of a validation error (and you probably do), then you need to understand how SAX error handling works.&lt;br /&gt;Converting Existing Data: There is a mechanism we can use to convert an existing data set to XML. However, taking advantage of that mechanism requires an understanding of the SAX model.&lt;br /&gt;&lt;br /&gt;SAX is fast and efficient, but its event model makes it most useful for such state-independent filtering. For example, a SAX parser calls one method in your application when an element tag is encountered and calls a different method when text is found. If the processing you're doing is state-independent (meaning that it does not depend on the elements have come before), then SAX works fine. &lt;br /&gt;&lt;br /&gt;On the other hand, for state-dependent processing, where the program needs to do one thing with the data under element A but something different with the data under element B, then a pull parser such as the Streaming API for XML (StAX) would be a better choice. With a pull parser, you get the next node, whatever it happens to be, at any point in the code that you ask for it. So it's easy to vary the way you process text (for example), because you can process it multiple places in the program.&lt;br /&gt;&lt;br /&gt;SAX requires much less memory than DOM, because SAX does not construct an internal representation (tree structure) of the XML data, as a DOM does. Instead, SAX simply sends data to the application as it is read; your application can then do whatever it wants to do with the data it sees. &lt;br /&gt;&lt;br /&gt;Pull parsers and the SAX API both act like a serial I/O stream. You see the data as it streams in, but you can't go back to an earlier position or leap ahead to a different position. In general, such parsers work well when you simply want to read data and have the application act on it.&lt;br /&gt;But when you need to modify an XML structure--especially when you need to modify it interactively--an in-memory structure makes more sense. DOM is one such model.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-7319347368637160174?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/7319347368637160174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=7319347368637160174' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/7319347368637160174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/7319347368637160174'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2008/01/java-api-for-xml-processing.html' title='Java API for XML Processing'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_h8w_fktOw40/R3scj3QMhkI/AAAAAAAAAAw/GQjK5enjJE4/s72-c/jaxpintro-saxApi.gif' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-1437399442625275627</id><published>2007-12-27T20:40:00.000-08:00</published><updated>2007-12-27T20:41:25.311-08:00</updated><title type='text'>Handle SQL date</title><content type='html'>To get the current date in SQL format. &lt;br /&gt;java.util.Date today =&lt;br /&gt;        new java.util.Date();&lt;br /&gt;java.sql.Date sqlToday =&lt;br /&gt;   new java.sql.Date(today.getTime());&lt;br /&gt;For Timestamp, it's the same idea &lt;br /&gt;java.util.Date today =&lt;br /&gt;        new java.util.Date();&lt;br /&gt;java.sql.Timestamp now =&lt;br /&gt;    new java.sql.Timestamp(today.getTime());&lt;br /&gt;To use a Date, Time or Timestamp in a query, you can use JDBC escape codes. &lt;br /&gt;Date       {d 'yyyy-mm-dd'}&lt;br /&gt;Time       {t {'hh:mm:ss'}&lt;br /&gt;Timestamp  {ts `yyyy-mm-dd hh:mm:ss.f . . .'}&lt;br /&gt;note: the .f .... is optional&lt;br /&gt;For example, a Statement with a Date will look like this &lt;br /&gt;java.util.Date today =&lt;br /&gt;        new java.util.Date();&lt;br /&gt;java.sql.Date sqlToday =&lt;br /&gt;        new java.sql.Date(today.getTime());&lt;br /&gt;&lt;br /&gt;String query =&lt;br /&gt;   "select * from cust where purchase_date &lt; { d '" &lt;br /&gt;       + sqlDate.toString() + "' }");&lt;br /&gt;&lt;br /&gt;With a PreparedStatement, you don't need JDBC escape codes, the JDBC driver will do the job for you. &lt;br /&gt;java.util.Date today =&lt;br /&gt;        new java.util.Date();&lt;br /&gt;java.sql.Date sqlToday =&lt;br /&gt;        new java.sql.Date(today.getTime());&lt;br /&gt;&lt;br /&gt;PreparedStatement p = theConn.prepareStatement&lt;br /&gt;   ("select * from cust where purchase_date &lt; ?");&lt;br /&gt;p.setDate(1, sqlToday);&lt;br /&gt;ResultSet rs = p.executeQuery();&lt;br /&gt;To INSERT &lt;br /&gt;PreparedStatement p = theConn.prepareStatement&lt;br /&gt;    ("insert into TableWithADateColumn values(?)");&lt;br /&gt;p.setDate(1, sqlToday);&lt;br /&gt;p.executeUpdate();&lt;br /&gt;or &lt;br /&gt;p.executeUpdate&lt;br /&gt;("insert into TableWithADateColumn values( { d '1999-12-31' } )");&lt;br /&gt;One thing to remember when using java.sql.date is (according to the javadoc) : &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To conform with the definition of SQL DATE, the millisecond values &lt;br /&gt;wrapped by a java.sql.Date instance must be 'normalized' by setting &lt;br /&gt;the hours, minutes, seconds, and milliseconds to zero in the particular &lt;br /&gt;time zone with which the instance is associated.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-1437399442625275627?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/1437399442625275627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=1437399442625275627' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1437399442625275627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1437399442625275627'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/12/handle-sql-date.html' title='Handle SQL date'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-1767981332689886231</id><published>2007-12-21T01:07:00.000-08:00</published><updated>2007-12-21T01:16:29.745-08:00</updated><title type='text'>How to load balance Tomcat 5.5 with Apache on Windows</title><content type='html'>How to load balance Tomcat 5.5 with Apache on Windows &lt;br /&gt;It's rather amazing that I could not find a single how-to that could detail the steps for using the Apache web server to load balance multiple Tomcat 5.5 instances on Windows. I found tons of articles- but they were either for older versions of Tomcat or Apache or for Unix flavors and none were accurate enough. Apache itself has fragmented documentation on the subject, and after much trial and error and pulling of hair, I succeeded.&lt;br /&gt;&lt;br /&gt;The least I can do is list the steps here for all others who have had trouble getting it right.&lt;br /&gt;The goal of this blog is to set up two Tomcat 5.5 instances with Apache in front, load balancing them. Please note that this does not cover clustering. I'll save that for another blog once I actually do it :-)&lt;br /&gt;Also, this is not a tutorial on load balancing. It will get you up and running- then you might want to look at the Tomcat documentation to find out what exactly all those options do.&lt;br /&gt;&lt;br /&gt;So, this is what you need to download:&lt;br /&gt;1. Apache HTTP server 2.2.4 from The Apache HTTP Server Project. I prefer the zip over the Windows Installer. You are free to choose the Windows Installer if you wish, but modify the service instructions below accordingly.&lt;br /&gt;&lt;br /&gt;2. Apache Tomcat 5.5.20 from Apache Tomcat downloads&lt;br /&gt;&lt;br /&gt;3. Mod JK Tomcat connector from here. Please note: You want to download the binary- click on JK 1.2 Binary Releases --&gt; win32 --&gt; jk-1.2.21 --&gt; mod_jk-apache-2.2.4.so&lt;br /&gt;&lt;br /&gt;Now let's start by installing Tomcat first.&lt;br /&gt;&lt;br /&gt;1. Extract the Tomcat zip. Hereafter, the directory you extracted to will be referred to as TOMCAT_HOME&lt;br /&gt;&lt;br /&gt;2. Test Tomcat to see that it works. Go to TOMCAT_HOME\bin and run startup.bat&lt;br /&gt;You may need to add an environment variable called CATALINA_HOME which is set to TOMCAT_HOME in case Tomcat fails to start.&lt;br /&gt;&lt;br /&gt;3. Open up your browser and access http://localhost:8080/&lt;br /&gt;If you see the default page, then Tomcat Instance 1 is working fine. Shut down Tomcat.&lt;br /&gt;&lt;br /&gt;4. Now set this up as a service. Go to your command prompt, change directory to TOMCAT_HOME\bin and set an environment variable called CATALINA_BASE. The value of this variable should again, be TOMCAT_HOME. For example:&lt;br /&gt;&lt;br /&gt;SET CATALINA_BASE=C:\Tomcat-5.5.20&lt;br /&gt;&lt;br /&gt;Then, execute the following: service install Tomcat5&lt;br /&gt;This will set up the Windows service for Tomcat.&lt;br /&gt;&lt;br /&gt;5. Go to your Services and see that Tomcat 5 is listed. Start the service, and then verify again that http://localhost:8080 is up.&lt;br /&gt;That's all for the first Tomcat instance. Now for the second.&lt;br /&gt;&lt;br /&gt;1. Make a directory called SecondInstance in TOMCAT_HOME&lt;br /&gt;&lt;br /&gt;2. Copy the conf, logs, shared, temp, webapps and work directories from the TOMCAT_HOME directory into the SecondInstance directory.&lt;br /&gt;&lt;br /&gt;3. Open up SecondInstance\conf\server.xml in a text editor. We've got to change the port numbers so that they don't conflict with the first instance.&lt;br /&gt;I just incremented by 10 and changed them as follows, but you could use other port numbers:&lt;br /&gt;&lt;br /&gt;&lt;Server port="8005" shutdown="SHUTDOWN"&gt; to &lt;Server port="8015" shutdown="SHUTDOWN"&gt;&lt;br /&gt;&lt;br /&gt;Connector port="8080" maxHttpHeaderSize="8192"... to Connector port="8090" maxHttpHeaderSize="8192"...&lt;br /&gt;&lt;br /&gt;&lt;Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /&gt; to &lt;Connector port="8019" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /&gt;&lt;br /&gt;&lt;br /&gt;Change the SSL port if you need it as well.&lt;br /&gt;&lt;br /&gt;4. Now set up the second instance to run as a service. Go to the command prompt, change to the TOMCAT_HOME\bin directory. Set the CATALINA_BASE environment variable to TOMCAT_HOME\SecondInstance. For example:&lt;br /&gt;&lt;br /&gt;SET CATALINA_BASE=C:\Tomcat5.5.20\SecondInstance&lt;br /&gt;Then, type:&lt;br /&gt;service install SecondTomcat&lt;br /&gt;&lt;br /&gt;Go to Services and start the SecondTomcat service. Test it out by pointing your browser to http://localhost:8090/&lt;br /&gt;Works ok? Great! Your second tomcat instance is now ready to be used.&lt;br /&gt;&lt;br /&gt;Next, let's set up the Apache HTTP Server. It's pretty simple...&lt;br /&gt;&lt;br /&gt;1. Run the installer you downloaded. The standard install will do.&lt;br /&gt;&lt;br /&gt;2. Open the Apache Server Monitor and start the web server if it's not already running.&lt;br /&gt;&lt;br /&gt;3. Point your browser to http://localhost/ to verify that Apache is running on port 80.&lt;br /&gt;&lt;br /&gt;4. Stop Apache.&lt;br /&gt;&lt;br /&gt;Finally, we reach mod JK. Let's set it up first just to delegate requests to the two Tomcat instances, and we'll load balance it a bit later.&lt;br /&gt;&lt;br /&gt;1. Copy the mod_jk-apache-2.2.4.so to the modules directory in your Apache installation.&lt;br /&gt;&lt;br /&gt;2. Rename it to mod_jk.so&lt;br /&gt;&lt;br /&gt;3. Open up httpd.conf in the conf directory of your Apache installation in a text edit, and add the following line at the end of the set of LoadModule statements:&lt;br /&gt;LoadModule jk_module modules/mod_jk.so&lt;br /&gt;&lt;br /&gt;4. Create a file called workers.properies in the conf directory. Add these lines to it:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;workers.tomcat_home=C:/tomcat-5.5.20&lt;br /&gt;&lt;br /&gt;workers.java_home=C:/jdk1.5.0_03&lt;br /&gt;&lt;br /&gt;worker.list=worker1,worker2&lt;br /&gt;&lt;br /&gt;worker.worker1.port=8009&lt;br /&gt;worker.worker1.host=localhost&lt;br /&gt;worker.worker1.type=ajp13&lt;br /&gt;&lt;br /&gt;worker.worker2.port=8019&lt;br /&gt;worker.worker2.host=localhost&lt;br /&gt;worker.worker2.type=ajp13&lt;br /&gt;&lt;br /&gt;This file defines which workers Apache can delegate to. We've listed worker1 and worker 2 to correspond to our two tomcat instances. Remember to set tomcat_home and java_home as well.&lt;br /&gt;&lt;br /&gt;5. Specify the worker properties in httpd.conf:&lt;br /&gt;&lt;br /&gt;Add these lines just after the LoadModule definitions-&lt;br /&gt;&lt;br /&gt;# Path to workers.properties&lt;br /&gt;JkWorkersFile c:/apache2.2/conf/workers.properties&lt;br /&gt;&lt;br /&gt;# Path to jk logs&lt;br /&gt;JkLogFile c:/apache2.2/mod_jk.log&lt;br /&gt;&lt;br /&gt;# Jk log level [debug/error/info]&lt;br /&gt;JkLogLevel info&lt;br /&gt;&lt;br /&gt;# Jk log format&lt;br /&gt;JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "&lt;br /&gt;&lt;br /&gt;# JkOptions for forwarding&lt;br /&gt;JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories&lt;br /&gt;&lt;br /&gt;# JkRequestLogFormat set the request format&lt;br /&gt;JkRequestLogFormat "%w %V %T"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;JkMount /jsp-examples worker1&lt;br /&gt;JkMount /jsp-examples/* worker1&lt;br /&gt;&lt;br /&gt;JkMount /tomcat-docs worker2&lt;br /&gt;JkMount /tomcat-docs/* worker2&lt;br /&gt;&lt;br /&gt;Defining these tells Apache where to look for definitions of its workers and tells it that any requests for the jsp-examples context should be handed off to the Tomcat instance represented by worker 1, and any requests for tomcat-docs context should be handed off to Tomcat Instance 2, represented by worker 2.&lt;br /&gt;&lt;br /&gt;5.5 [Added on April 11 2007]&lt;br /&gt;Edit the server.xml for Tomcat and Tomcat's SecondInstance and add a jvmRoute attribute to the Engine element:&lt;br /&gt;&lt;Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1"&gt;&lt;br /&gt;for the first instance and&lt;br /&gt;&lt;Engine name="Catalina" defaultHost="localhost" jvmRoute="worker2"&gt;&lt;br /&gt;for the second.&lt;br /&gt;&lt;br /&gt;6. Start Tomcat Instance 1 and 2. Start up the Apache webserver. Point your browser to http://localhost/jsp-examples/ and then to http://localhost/tomcat-docs. You should see the respective pages load. To distinguish which Tomcat is serving you the page, the easiest thing to do is edit the index page in the tomcat-docs and jsp-examples of Tomcat 2 and change the title for example. Then you can verify that tomcat-docs is being served only by the second instance.&lt;br /&gt;&lt;br /&gt;Thats it!! Apache is now delegating requests to both Tomcats.&lt;br /&gt;Now for our last task- we will load balance it so that Apache distributes load for jsp-examples between both instances of Tomcat. It also serves as a failover mechanism. If Tomcat 1 is down for whatever reason, Apache will automatically keep delegating to Tomcat 2 so your application remains accessible.&lt;br /&gt;&lt;br /&gt;Load balancing is a simple configuration. First shut down your Tomcat instances and Apache as well.&lt;br /&gt;&lt;br /&gt;1. Open workers.properties in a text editor.&lt;br /&gt;&lt;br /&gt;2. Edit it so it looks like this (changed lines in bold)-&lt;br /&gt;&lt;br /&gt;workers.tomcat_home=C:/tomcat-5.5.20&lt;br /&gt;workers.java_home=C:/jdk1.5.0_03&lt;br /&gt;&lt;br /&gt;#worker.list=worker1,worker2&lt;br /&gt;worker.list=balancer&lt;br /&gt;&lt;br /&gt;worker.worker1.port=8009&lt;br /&gt;worker.worker1.host=localhost&lt;br /&gt;worker.worker1.type=ajp13&lt;br /&gt;worker.worker1.lbfactor=1&lt;br /&gt;&lt;br /&gt;worker.worker2.port=8019&lt;br /&gt;worker.worker2.host=localhost&lt;br /&gt;worker.worker2.type=ajp13&lt;br /&gt;worker.worker2.lbfactor=1&lt;br /&gt;&lt;br /&gt;worker.balancer.type=lb&lt;br /&gt;worker.balancer.balance_workers=worker1,worker2&lt;br /&gt;worker.balancer.method=B&lt;br /&gt;&lt;br /&gt;We've changed the worker list to a single worker called balancer, and specified that the worker type of balancer is 'lb' or load balancer. The workers it manages are worker1 and worker2 (these do not need to appear in the workers list). And finally, we set the balance method to 'B' or balance by busy factor. Apache will delegate the next request to the Tomcat instance which is least busy. Please note that there are a couple of options for method- consult the Apache/Tomcat documentation which lists out options for workers properties to help you decide the best method for your type of application.&lt;br /&gt;&lt;br /&gt;3. Open httpd.conf and comment out the previous JkMount directives. Replace them with these:&lt;br /&gt;&lt;br /&gt;JkMount /jsp-examples balancer&lt;br /&gt;JkMount /jsp-examples/* balancer&lt;br /&gt;&lt;br /&gt;Very simple- we've just pointed Apache to a single worker- the balancer.&lt;br /&gt;&lt;br /&gt;4. Start up both Tomcats and Apache. Access http://localhost/jsp-examples&lt;br /&gt;You will either be served by Tomcat 1 or Tomcat 2. To prove that both are capable of serving, shut down the first instance and refresh your browser. You should be served by instance two.&lt;br /&gt;&lt;br /&gt;Congratulations! You've successfully set up Apache load balancing multiple tomcat instances!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-1767981332689886231?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/1767981332689886231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=1767981332689886231' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1767981332689886231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1767981332689886231'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/12/how-to-load-balance-tomcat-55-with.html' title='How to load balance Tomcat 5.5 with Apache on Windows'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-1079097043578977716</id><published>2007-12-13T04:23:00.000-08:00</published><updated>2007-12-13T04:29:10.842-08:00</updated><title type='text'>MySQL ssh tunnel</title><content type='html'>1.&lt;br /&gt;On your home machine: &lt;br /&gt;ssh -L 3307:domain.name.of.mysqlserver:3306 username@domain.name.of.gatewayserver&lt;br /&gt;&lt;br /&gt;Ex:&lt;br /&gt;$ ssh -L 3307:dbserver:3306 ananth@xxx.xxxxxxx.xxx&lt;br /&gt;&lt;br /&gt;This will open a tunnel, listening on localhost:3307 and forwarding everything to mysqlserver:3306, and doing it all via the ssh service on the gateway machine.&lt;br /&gt;&lt;br /&gt;2.&lt;br /&gt;Now, on your local machine, execute a mysql connection like so: &lt;br /&gt;mysql -u username -p -h 127.0.0.1 -P 3307 databasename&lt;br /&gt;&lt;br /&gt;Ex:&lt;br /&gt;C:\Program Files\MySQL\MySQL Server 5.0\bin&gt;mysql -u USERNAME -pPASSWORD -h 127.0.0.1 -P 3307 DATABASENAME&lt;br /&gt;&lt;br /&gt;In other words, mysql thinks it's connecting to localhost, but on a different port. In fact, the connection is being made securely to the remote mysql server, via the gateway machine and the local "mouth" of the ssh tunnel on your own machine. &lt;br /&gt;&lt;br /&gt;3.&lt;br /&gt;When you're finished with your mysql session, log out of the session on the gateway machine. That will properly close the tunnel.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-1079097043578977716?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/1079097043578977716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=1079097043578977716' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1079097043578977716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1079097043578977716'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/12/mysql-ssh-tunnel.html' title='MySQL ssh tunnel'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-8792138715659673768</id><published>2007-10-15T02:17:00.000-07:00</published><updated>2007-10-15T02:18:50.163-07:00</updated><title type='text'>Beginning J2EE</title><content type='html'>This article provides a high-level introduction to J2EE. It is taken from chapter one of the book Beginning J2EE 1.4 From Novice to Professional, written by James L. Weaver, Kevin Mukhar, and Jim Crume (Apress, 2004; ISBN: 1590593413).&lt;br /&gt;&lt;br /&gt;The word “enterprise” has magical powers in computer programming circles. It can increase the price of a product by an order of magnitude, and double the potential salary of an experienced consultant. Your application may be free of bugs, and cleanly coded using all the latest techniques and tools, but is it enterprise ready? What exactly is the magic ingredient that makes enterprise development qualitatively different from run-of-the-mill development?&lt;br /&gt;&lt;br /&gt;Enterprise applications solve business problems. This usually involves the safe storage, retrieval, and manipulation of business data: customer invoices, mortgage applications, flight bookings, and so on. They might have multiple user interfaces: a web interface for consumers, and a GUI application running on computers in the branch offices, for example. They have to deal with communication between remote systems, co-ordination of data in multiple stores, and ensure the system always follows the rules laid down by the business. If any part of the system crashes, the business loses part of its ability to function, and starts to lose money. If the business grows, the application needs to grow with it. All this adds up to what characterizes enterprise applications: robustness in the face of complexity.&lt;br /&gt;&lt;br /&gt;When we set out to build a GUI application, we don’t start out by working out how to draw pixels on the screen, and build our own code to track the user’s mouse around the screen; we rely on a GUI library, like Swing, to do that for us. Similarly, when we set out to create the components of a full-scale enterprise solution, we’d be crazy to start from scratch. Enterprise programmers build their applications on top   of systems called application servers. Just as GUI toolkits provide services of use to GUI applications, application servers provide services of use to enterprise applications – things like communication facilities to talk to other computers, management of database connections,   the ability to serve web pages, and management of transactions.&lt;br /&gt;&lt;br /&gt;Just as Java provides a uniform way to program GUI applications on any underlying operating system, nowadays Java can provide a uniform way to program enterprise applications on any underlying application server. The set of libraries developed by Sun Microsystems and the Java Community Process that represent this uniform application server API is what we call the Java 2 Platform, Enterprise Edition, and is the subject of this book.&lt;br /&gt;&lt;br /&gt;This chapter provides a high-level introduction to J2EE, and an introduction on how to get the most benefit from this book. After reading this chapter, you will:&lt;br /&gt;Have an understanding of the reasons why the concepts underlying J2EE are compelling and enabling technologies for large-scale applications &lt;br /&gt;Understand how J2EE relates to J2SE &lt;br /&gt;Be introduced to the cornerstone technologies of J2EE &lt;br /&gt;Be introduced to some of the essential architectural patterns that J2EE facilitates &lt;br /&gt;&lt;br /&gt;So, without further ado, let’s get started!&lt;br /&gt;What Is J2EE? &lt;br /&gt;&lt;br /&gt;Since you’re reading this book you’ve got some interest in J2EE, and probably have some notion of what you’re getting into. For many fledgling J2EE developers, J2EE equates to Enterprise JavaBeans. J2EE is a great deal more than just EJBs, though.&lt;br /&gt;&lt;br /&gt;While perhaps an oversimplification, J2EE is a suite of specifications for application programming interfaces, a distributed computing architecture, and definitions for packaging of distributable components for deployment. It’s a collection of standardized components, containers, and services for creating and deploying distributed applications within a well-defined distributed computing architecture.&lt;br /&gt;&lt;br /&gt;As its name pretty much spells out, Java 2 Enterprise Edition is targeted at large-scale business systems. Software that functions at that level doesn’t run on a single PC—it requires significantly more computing power and throughput than that. For that reason, the software needs to be partitioned into functional pieces and deployed on the appropriate hardware platforms to provide the necessary computing power. That is the essence of distributed computing. J2EE provides a collection of standardized components that facilitate software deployment, standard interfaces that define how the various software modules interconnect, and standard services that define how the different software modules communicate.&lt;br /&gt;How J2EE Relates to J2SE &lt;br /&gt;&lt;br /&gt;J2EE isn’t a replacement for the Java 2 Standard Edition. The J2SE provides the essential language framework that the J2EE builds upon. It is the core upon which J2EE is based. As you’ll see, J2EE consists of several layers, and J2SE is right at the base of that pyramid for each component of J2EE.&lt;br /&gt;&lt;br /&gt;As a Java developer, you’ve probably already learned how to build user interfaces with the JFC/Swing and AWT components. You’ll still be using those to build the user interfaces for your J2EE applications, as well as HTML-based user interfaces. Since J2SE is at the core of J2EE, everything that you’ve learned so far remains useful and relevant.&lt;br /&gt;&lt;br /&gt;In fact, J2EE provides pretty much nothing in the way of user interfaces. You’ll also see that the J2EE platform provides the most significant benefit in developing the “middle tier” portion of your application—that’s the business logic and the connections to back-end data sources. You’ll use familiar J2SE components and APIs in conjunction with the J2EE components and APIs to build that part of your applications.&lt;br /&gt;Why J2EE? &lt;br /&gt;&lt;br /&gt;J2EE defines a number of services that, to someone developing enterprise-class applications, are as essential as electricity and running water. Life is simple when you simply turn the faucet and water starts running, or flip the switch and lights come on. If you have ever been involved with building a house, you’ll know that there is a great deal of effort, time, and expense in building in that infrastructure of plumbing and wiring that is then so nicely hidden behind freshly painted walls. At the points where that infrastructure is exposed, there are standard interfaces for controlling (water faucets and light switches, for example) and connecting (power sockets, lamp sockets, and hose bibs, for example).&lt;br /&gt;&lt;br /&gt;In the same vein, there is a great deal of infrastructure required to write enterprise-class applications. There are a bunch of different system-level capabilities that you need in order to write distributed applications that are scaleable, robust, secure, and maintainable. Some vital pieces of that infrastructure include security, to ensure that a user is who they claim to be, and can only access the parts of the application that they’re entitled to access. Database access is also a fundamental component so that your application can store and retrieve data. Transaction support is required to make sure that the right data is updated at the right time. If you’re not familiar with some of these concepts, don’t worry—you’ll be introduced to them one at a time throughout this book.&lt;br /&gt;&lt;br /&gt;Suppose, though, that the wiring and plumbing in your home wasn’t there. You’d need to put in your own plumbing and electricity. Without standard components and interfaces, though, you’d have to fabricate your own pipes, wiring, and so on—it’d be terrifically expensive and an awful lot of work.&lt;br /&gt;&lt;br /&gt;Putting in a distributed computing infrastructure—the plumbing and wiring of an architecture that supports enterprise applications—is no simple feat. That’s why J2EE-based architectures are so compelling—the hard system-level infrastructure is already in place. But why not custom build (or pay someone to custom build) an infrastructure that is designed around your particular application? Well, for starters, it would take a fantastic amount of time, money, and effort. And even if you were to build up that infrastructure, it would be different from anyone else’s infrastructure, so you’d not be able to share components or interoperate with anyone else’s distributed computing model. That’s a lot of work for something that sounds like a dead end. Even if you were lucky enough to find a vendor that could sell you a software infrastructure, you should be wary about any solution that would lock you into any single vendor’s implementation that would preclude you from switching vendors at some point in the future.&lt;br /&gt;&lt;br /&gt;The good news is, no surprise, that J2EE defines a set of containers, connectors, and components that fill that gap. J2EE not only fills the gap, but it’s based on well-known, published specifications. That means that applications written for J2EE will run on any number of J2EE-compliant implementations. The reference implementation supplied with the J2EE Software Development Kit from Sun (J2SDKEE) provides a working model that we’ll use throughout this book, since it’s the implementation that Sun has built from the specification, and is freely available. In the next chapter you’ll get an introduction to installing and testing the J2SDKEE.&lt;br /&gt;&lt;br /&gt;It’s important to note that the reference implementation is a working model but it’s not designed to be used for enterprise-level deployment. It doesn’t provide some of the enterprise-level features that are outside of the scope of the J2EE specification, such as clustering (the ability to have multiple servers handling requests at the same time) or failover (the ability to have a group of servers that can recover when one crashes). Working with the reference implementation, though, ensures that you’ll get exposure to the core J2EE concepts that apply to ALL vendor implementations, and you won’t get bogged down with vendor-specific details.&lt;br /&gt;&lt;br /&gt;For production deployment, you’ll want to select one of a number of J2EE solutions available from a number of different vendors, which have been optimized for high volume throughput and are designed for your particular application. Sun (http://www.sun.com/software), IBM (http://www.ibm.com/websphere), Borland (http://www. borland.com/besappserver) and BEA (http://www.bea.com/ products/weblogic/server) are high-profile examples—but certainly not all—of the commercial implementations. JBoss (http:// www.jboss.org) is an open source implementation that has a huge following. You get to choose which one works best for you—that’s an exercise that’s beyond the scope of this book.&lt;br /&gt;&lt;br /&gt;Building a J2EE application for one J2EE implementation and deploying it on another is cheap, but it’s not free, nor is each vendor’s implementation of J2EE completely free of defects and operational quirks. Although Java and J2EE go a long way towards providing platform independence, that isn’t a guarantee that you can develop on one platform and deploy on another without any hiccups or surprises. Bugs, differences in performance, and other little “gotchas” can seriously delay or derail your project. When you are developing systems that will be deployed in a production environment, it is always a good idea to do your development and staging using the same platforms and technologies that the production environment is based upon. This will help to avoid unnecessary surprises during and after the rollout.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-8792138715659673768?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/8792138715659673768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=8792138715659673768' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/8792138715659673768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/8792138715659673768'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/10/beginning-j2ee.html' title='Beginning J2EE'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-6634513062110131926</id><published>2007-09-12T08:37:00.000-07:00</published><updated>2007-09-12T08:40:45.307-07:00</updated><title type='text'>Interface vs. abstract class</title><content type='html'>Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks. &lt;br /&gt;&lt;br /&gt;Abstract classes let you define some behaviors; they force your subclasses to provide others. For example, if you have an application framework, an abstract class may provide default services such as event and message handling. Those services allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform. Such functionality might include startup and shutdown tasks, which are often application-dependent. So instead of trying to define that behavior itself, the abstract base class can declare abstract shutdown and startup methods. The base class knows that it needs those methods, but an abstract class lets your class admit that it doesn't know how to perform those actions; it only knows that it must initiate the actions. When it is time to start up, the abstract class can call the startup method. When the base class calls this method, Java calls the method defined by the child class.  &lt;br /&gt;&lt;br /&gt;Many developers forget that a class that defines an abstract method can call that method as well. Abstract classes are an excellent way to create planned inheritance hierarchies. They're also a good choice for nonleaf classes in class hierarchies. &lt;br /&gt;&lt;br /&gt; Q: Why use interfaces to develop Java applications? &lt;br /&gt;A: It is advisable to design relatively large applications using interfaces because it makes the whole system easier to modify, extend and integrate new features. To start with, you may only have one implementation of a given interface, but if you find you need slightly different behaviour in special circumstances, you only need write a class that conforms to one of the existing interfaces and it will drop in place without major modifications. &lt;br /&gt;&lt;br /&gt;Interfaces also allow you to adapt a class from a different hierarchy to work in an existing application. The class only needs to declare it implements the interface, provide the necessary methods and it can be integrated directly as if it were created for the job. &lt;br /&gt;&lt;br /&gt;Q: What is the difference between abstract classes and interfaces? &lt;br /&gt;A: A Java interface is a definition of a class type without any concrete implementation. Typically, an interface consists of one or more method signatures that a subclass must fulfil to conform to the type. In effect, all their methods are abstract, and interfaces cannot be instantiated&lt;br /&gt;&lt;br /&gt;Q: Do interfaces have member variables? &lt;br /&gt;A: Interfaces may have member variables, but these are implicitly final and static because they are not inherited by extension. In effect interface variables are constants that are available to all implementations and may be used as key references for method arguments for example. &lt;br /&gt;&lt;br /&gt;Q: Can we create an object for an interface? &lt;br /&gt;A: Yes, it is always necessary to create an object implementation for an interface. Interfaces cannot be instantiated in their own right, so you must write a class that implements the interface and fulfil all the methods defined in it. &lt;br /&gt;&lt;br /&gt;public class Concrete implements ExampleInterface {&lt;br /&gt;&lt;br /&gt;  ...&lt;br /&gt;}&lt;br /&gt;      Q: What is a marker interface? &lt;br /&gt;A: Marker interfaces are those which do not declare any required methods, but signify their compatibility with certain operations. The java.io.Serializable interface is a typical marker interface. It does not contain any methods, but classes must implement this interface in order to be serialized and de-serialized. &lt;br /&gt;&lt;br /&gt;Q: Should I use a public access modifier for interface methods? &lt;br /&gt;A: Java interfaces are used to define a public Application Programming Interface (API) for classes to implement, so a public modifier is redundant in this context. Non-public modifiers are not valid for interfaces, so the compiler should fail and warn you in this case. &lt;br /&gt;&lt;br /&gt;Interface usage &lt;br /&gt;Q: What are the rules for passing subclasses for method arguments? &lt;br /&gt;A: It may help to discuss an example using birds: an interface called Avian, a superclass FlyingBird that implements Avian and two concrete classes: Parrot and Penguin. Parrot extends FlyingBird, so is implicitly an Avian type, but Penguin does not, it only implements Avian. The examples below work through all possibilities, passing references to methods soundBirdCall(FlyingBird) and displayPlumage(Avian)&lt;br /&gt;&lt;br /&gt;Q: When should I use abstract classes rather than interfaces? &lt;br /&gt;A: Abstract classes are are often used to provide methods that will be common to a range of similar subclasses, to avoid duplicating the same code in each case. Each subclass adds its own features on top of the common abstract methods. &lt;br /&gt;&lt;br /&gt;Q: Can an interface be declared final? &lt;br /&gt;A: It is not permitted to declare an interface as final, it will cause a compilation error. It does not make sense to declare an interface final because it contains no implementation code and cannot instantiated in its own right. The final modifier is used to prevent the extension of concrete classes. &lt;br /&gt;&lt;br /&gt;Q: This code seems to be instantiating an interface! &lt;br /&gt;A: The code you are looking at declares an inline anonymous class that implements an interface, which has a similar effect. This declaration does not instantiate the interface, but defines the type of the anonymous class, which has no name of its own. This approach is often used in AWT or Swing applications where a class is required to fulfil a minimal interface and it is not necessary to retain a reference to it by assignment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-6634513062110131926?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/6634513062110131926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=6634513062110131926' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/6634513062110131926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/6634513062110131926'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/09/interface-vs-abstract-class.html' title='Interface vs. abstract class'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-4344904251999616726</id><published>2007-09-12T08:22:00.001-07:00</published><updated>2007-09-12T08:22:37.171-07:00</updated><title type='text'>Ocerriding vs Hiding</title><content type='html'>Can I override a static method? &lt;br /&gt;Many people have heard that you can't override a static method. This is true - you can't. However it is possible to write code like this:&lt;br /&gt;&lt;br /&gt;class Foo {&lt;br /&gt;    public static void method() {&lt;br /&gt;        System.out.println("in Foo");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;//commited  by  sanjay&lt;br /&gt;class Bar extends Foo {&lt;br /&gt;    public static void method() {&lt;br /&gt;        System.out.println("in Bar");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;This compiles and runs just fine. Isn't it an example of a static method overriding another static method? The answer is no - it's an example of a static method hiding another static method. If you try to override a static method, the compiler doesn't actually stop you - it just doesn't do what you think it does. &lt;br /&gt;So what's the difference? &lt;br /&gt;&lt;br /&gt;Briefly, when you override a method, you still get the benefits of run-time polymorphism, and when you hide, you don't. So what does that mean? Take a look at this code:&lt;br /&gt;&lt;br /&gt;class Foo {&lt;br /&gt;    public static void classMethod() {&lt;br /&gt;        System.out.println("classMethod() in Foo");&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void instanceMethod() {&lt;br /&gt;        System.out.println("instanceMethod() in Foo");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Bar extends Foo {&lt;br /&gt;    public static void classMethod() {&lt;br /&gt;        System.out.println("classMethod() in Bar");&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void instanceMethod() {&lt;br /&gt;        System.out.println("instanceMethod() in Bar");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;class Test {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        Foo f = new Bar();&lt;br /&gt;        f.instanceMethod();&lt;br /&gt;        f.classMethod();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;If you run this, the output is&lt;br /&gt;instanceMethod() in Bar&lt;br /&gt;classMethod() in Foo&lt;br /&gt;Why do we get instanceMethod from Bar, but classMethod() from Foo? Aren't we using the same instance f to access both of these? Yes we are - but since one is overriding and the other is hiding, we see different behavior. &lt;br /&gt;Since instanceMethod() is (drum roll please...) an instance method, in which Bar overrides the method from Foo, at run time the JVM uses the actual class of the instance f to determine which method to run. Although f was declared as a Foo, the actual instance we created was a new Bar(). So at runtime, the JVM finds that f is a Bar instance, and so it calls instanceMethod() in Bar rather than the one in Foo. That's how Java normally works for instance methods. &lt;br /&gt;&lt;br /&gt;With classMethod() though. since (ahem) it's a class method, the compiler and JVM don't expect to need an actual instance to invoke the method. And even if you provide one (which we did: the instance referred to by f) the JVM will never look at it. The compiler will only look at the declared type of the reference, and use that declared type to determine, at compile time, which method to call. Since f is declared as type Foo, the compiler looks at f.classMethod() and decides it means Foo.classMethod. It doesn't matter that the instance reffered to by f is actually a Bar - for static methods, the compiler only uses the declared type of the reference. That's what we mean when we say a static method does not have run-time polymorphism. &lt;br /&gt;&lt;br /&gt;Because instance methods and class methods have this important difference in behavior, we use different terms - "overriding" for instance methods and "hiding" for class methods - to distinguish between the two cases. And when we say you can't override a static method, what that means is that even if you write code that looks like it's overriding a static method (like the first Foo and Bar at the top of this page) - it won't behave like an overridden method. &lt;br /&gt;&lt;br /&gt;So what about accessing a static method using an instance? &lt;br /&gt;&lt;br /&gt;It's possible in Java to write something like: &lt;br /&gt;&lt;br /&gt;   f.classMethod();&lt;br /&gt;] where f is an instance of some class, and classMethod() is a class method (i.e. a static method) of that class. This is legal, but it's a bad idea because it creates confusion. The actual instance f is not really important here. Only the decleared type of f matters. That is, what class is f declared to be? Since classMethod() is static, the class of f (as determined by the compiler at compile time) is all we need. &lt;br /&gt;Rather than writing:&lt;br /&gt;&lt;br /&gt;    f.classMethod();&lt;br /&gt;It would be better coding style to write either:&lt;br /&gt;    Foo.classMethod();&lt;br /&gt;or&lt;br /&gt;    Bar.classMethod(); &lt;br /&gt;That way, it is crystal clear which class method you would like to call. It is also clear that the method you are calling is indeed a class method. &lt;br /&gt;Barring that, you could always come up with this monstrosity:&lt;br /&gt;&lt;br /&gt;    f.getClass().getMethod("classMethod", new Class[]).invoke(f, new Object[]);&lt;br /&gt;But all this could be avoided by simply not trying to override your static (class) methods. :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-4344904251999616726?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/4344904251999616726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=4344904251999616726' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4344904251999616726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4344904251999616726'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/09/ocerriding-vs-hiding.html' title='Ocerriding vs Hiding'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-3180861944189297075</id><published>2007-09-11T05:36:00.000-07:00</published><updated>2007-09-11T05:40:40.011-07:00</updated><title type='text'>Java Virtual Machine</title><content type='html'>&lt;span style="font-weight:bold;"&gt;What is the Java Virtual Machine? Why is it here?&lt;/span&gt;&lt;br /&gt;The Java Virtual Machine, or JVM, is an abstract computer that runs compiled Java programs. The JVM is "virtual" because it is generally implemented in software on top of a "real" hardware platform and operating system. All Java programs are compiled for the JVM. Therefore, the JVM must be implemented on a particular platform before compiled Java programs will run on that platform. &lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_h8w_fktOw40/RuaMe2AGlsI/AAAAAAAAAAg/vKRnTnBmo5s/s1600-h/Sandwich.gif"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_h8w_fktOw40/RuaMe2AGlsI/AAAAAAAAAAg/vKRnTnBmo5s/s200/Sandwich.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5108925288818316994" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The JVM plays a central role in making Java portable. It provides a layer of abstraction between the compiled Java program and the underlying hardware platform and operating system. The JVM is central to Java's portability because compiled Java programs run on the JVM, independent of whatever may be underneath a particular JVM implementation. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What makes the JVM lean and mean? The JVM is lean because it is small when implemented in software. It was designed to be small so that it can fit in as many places as possible -- places like TV sets, cell phones, and personal computers. The JVM is mean because it of its ambition. "Ubiquity!" is its battle cry. It wants to be everywhere, and its success is indicated by the extent to which programs written in Java will run everywhere. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Java bytecodes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Java programs are compiled into a form called Java bytecodes. The JVM executes Java bytecodes, so Java bytecodes can be thought of as the machine language of the JVM. The Java compiler reads Java language source (.java) files, translates the source into Java bytecodes, and places the bytecodes into class (.class) files. The compiler generates one class file per class in the source. &lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_h8w_fktOw40/RuaMq2AGltI/AAAAAAAAAAo/EVr6zLCD4Ko/s1600-h/Filter.gif"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_h8w_fktOw40/RuaMq2AGltI/AAAAAAAAAAo/EVr6zLCD4Ko/s200/Filter.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5108925494976747218" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To the JVM, a stream of bytecodes is a sequence of instructions. Each instruction consists of a one-byte opcode and zero or more operands. The opcode tells the JVM what action to take. If the JVM requires more information to perform the action than just the opcode, the required information immediately follows the opcode as operands. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A mnemonic is defined for each bytecode instruction. The mnemonics can be thought of as an assembly language for the JVM.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-3180861944189297075?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/3180861944189297075/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=3180861944189297075' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/3180861944189297075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/3180861944189297075'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/09/java-virtual-machine.html' title='Java Virtual Machine'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_h8w_fktOw40/RuaMe2AGlsI/AAAAAAAAAAg/vKRnTnBmo5s/s72-c/Sandwich.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-530307989180428284</id><published>2007-09-11T05:01:00.000-07:00</published><updated>2007-09-11T05:05:41.443-07:00</updated><title type='text'>Java bytecode:</title><content type='html'>This article gives you an understanding of Java bytecode that will enable you to be a better programmer. Like a C or C++ compiler translates source code into assembler code, Java compilers translate Java source code into bytecode. Java programmers should take the time to understand what the bytecode is, how it works, and most importantly, what bytecode is being generated by the Java compiler.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Why understand bytecode?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Bytecode is the intermediate representation of Java programs just as assembler is the intermediate representation of C or C++ programs. The most knowlegable C and C++ programmers know the assembler instruction set of the processor for which they are compiling. This knowledge is crucial when debugging and doing performance and memory usage tuning. Knowing the assembler instructions that are generated by the compiler for the source code you write, helps you know how you might code differently to achieve memory or performance goals. In addition, when tracking down a problem, it is often useful to use a debugger to disassemble the source code and step through the assembler code that is executing. &lt;br /&gt;&lt;br /&gt;An often overlooked aspect of Java is the bytecode that is generated by the javac compiler. Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembler helps the C or C++ programmer. &lt;br /&gt;&lt;br /&gt;The bytecode is your program. Regardless of a JIT or Hotspot runtime, the bytecode is an important part of the size and execution speed of your code. Consider that the more bytecode you have, the bigger the .class file is and the more code that has to be compiled by a JIT or Hotspot runtime. The remainder of this article gives you an in depth look at Java bytecode. &lt;br /&gt;&lt;br /&gt;Generating bytecode&lt;br /&gt;&lt;br /&gt;javac Employee.java&lt;br /&gt;javap -c Employee &gt; Employee.bc&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Compiled from Employee.java&lt;br /&gt;class Employee extends java.lang.Object {&lt;br /&gt;public Employee(java.lang.String,int);&lt;br /&gt;public java.lang.String employeeName();&lt;br /&gt;public int employeeNumber();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Method Employee(java.lang.String,int)&lt;br /&gt;0 aload_0&lt;br /&gt;1 invokespecial #3 &lt;Method java.lang.Object()&gt;&lt;br /&gt;4 aload_0&lt;br /&gt;5 aload_1&lt;br /&gt;6 putfield #5 &lt;Field java.lang.String name&gt;&lt;br /&gt;9 aload_0&lt;br /&gt;10 iload_2&lt;br /&gt;11 putfield #4 &lt;Field int idNumber&gt;&lt;br /&gt;14 aload_0&lt;br /&gt;15 aload_1&lt;br /&gt;16 iload_2&lt;br /&gt;17 invokespecial #6 &lt;Method void storeData(java.lang.String, int)&gt;&lt;br /&gt;20 return&lt;br /&gt;&lt;br /&gt;Method java.lang.String employeeName()&lt;br /&gt;0 aload_0&lt;br /&gt;1 getfield #5 &lt;Field java.lang.String name&gt;&lt;br /&gt;4 areturn&lt;br /&gt;&lt;br /&gt;Method int employeeNumber()&lt;br /&gt;0 aload_0&lt;br /&gt;1 getfield #4 &lt;Field int idNumber&gt;&lt;br /&gt;4 ireturn&lt;br /&gt;&lt;br /&gt;Method void storeData(java.lang.String, int)&lt;br /&gt;0 return&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This class is very simple. It contains two instance variables, a constructor and three methods. The first five lines of the bytecode file list the file name that is used to generate this code, the class definition, its inheritance (by default, all classes inherit from java.lang.Object ), and its constructors and methods. Next, the bytecode for each of the constructors is listed. Then, each method is listed in alphabetical order with its associated bytecode. &lt;br /&gt;&lt;br /&gt;You might notice on closer inspection of the bytecode that certain opcodes are prefixed with an `a' or an `i'. For example, in the Employee class constructor you see aload_0 and iload_2. The prefix is representative of the type that the opcode is working with. The prefix `a' means that the opcode is manipulating an object reference. The prefix `i' means the opcode is manipulating an integer. Other opcodes use `b' for byte, `c' for char, `d' for double, etc. This prefix gives you immediate knowledge about what type of data is being manipulated.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;The details&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To understand the details of the bytecode, we need to discuss how a Java Virtual Machine (JVM) works regarding the execution of the bytecode. A JVM is a stack-based machine. Each thread has a JVM stack which stores frames. A frame is created each time a method is invoked, and consists of an operand stack, an array of local variables, and a reference to the runtime constant pool of the class of the current method. Conceptually, it might look like this: &lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_h8w_fktOw40/RuaEHmAGlrI/AAAAAAAAAAY/0KDtIXu5NGY/s1600-h/bytecode_1.gif"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://bp0.blogger.com/_h8w_fktOw40/RuaEHmAGlrI/AAAAAAAAAAY/0KDtIXu5NGY/s200/bytecode_1.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5108916093293336242" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The array of local variables, also called the local variable table, contains the parameters of the method and is also used to hold the values of the local variables. The parameters are stored first, beginning at index 0. If the frame is for a constructor or an instance method, the reference is stored at location 0. Then location 1 contains the first formal parameter, location 2 the second, and so on. For a static method, the first formal method parameter is stored in location 0, the second in location 1, and so on. &lt;br /&gt;&lt;br /&gt;The size of the array of local variables is determined at compile time and is dependent on the number and size of local variables and formal method parameters. The operand stack is a LIFO stack used to push and pop values. Its size is also determined at compile time. Certain opcode instructions push values onto the operand stack; others take operands from the stack, manipulate them, and push the result. The operand stack is also used to receive return values from methods. &lt;br /&gt;&lt;br /&gt;public String employeeName()&lt;br /&gt;{&lt;br /&gt;return name;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Method java.lang.String employeeName()&lt;br /&gt;0 aload_0&lt;br /&gt;1 getfield #5 &lt;Field java.lang.String name&gt;&lt;br /&gt;4 areturn&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The bytecode for this method consists of three opcode instructions. The first opcode, aload_0, pushes the value from index 0 of the local variable table onto the operand stack. Earlier, it was mentioned that the local variable table is used to pass parameters to methods. The this reference is always stored at location 0 of the local variable table for constructors and instance methods. The this reference must be pushed because the method is accessing the instance data, name, of the class.&lt;br /&gt;&lt;br /&gt;The next opcode instruction, getfield, is used to fetch a field from an object. When this opcode is executed, the top value from the stack, this, is popped. Then the #5 is used to build an index into the runtime constant pool of the class where the reference to name is stored. When this reference is fetched, it is pushed onto the operand stack. &lt;br /&gt;&lt;br /&gt;The last instruction, areturn, returns a reference from a method. More specifically, the execution of areturn causes the top value on the operand stack, the reference to name, to be popped and pushed onto the operand stack of the calling method.&lt;br /&gt;&lt;br /&gt;The employeeName method is fairly simple. Before looking at a more complex example, we need to examine the values to the left of each opcode. In the employeeName method's bytecode, these values are 0, 1, and 4. Each method has a corresponding bytecode array. These values correspond to the index into the array where each opcode and its arguments are stored. You might wonder why the values are not sequential. Since bytecode got its name because each instruction occupies one byte, why are the indexes not 0, 1, and 2? The reason is some of the opcodes have parameters that take up space in the bytecode array. For example, the aload_0 instruction has no parameters and naturally occupies one byte in the bytecode array. Therefore, the next opcode, getfield, is in location 1. However, areturn is in location 4. This is because the getfield opcode and its parameters occupy location 1, 2, and 3. Location 1 is used for the getfield opcode, location 2 and 3 are used to hold its parameters. These parameters are used to construct an index into the runtime constant pool for the class to where the value is stored. The following diagram shows what the bytecode array looks like for the employeeName method:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Actually, the bytecode array contains bytes that represent the instructions. Looking at a .class file with a hex editor, you would see the following values in the bytecode array: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2A , B4 , and B0 correspond to aload_0, getfield, and areturn, respectively.&lt;br /&gt;&lt;br /&gt;public Employee(String strName, int num)&lt;br /&gt;{&lt;br /&gt;name = strName;&lt;br /&gt;idNumber = num;&lt;br /&gt;storeData(strName, num);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Method Employee(java.lang.String,int)&lt;br /&gt;0 aload_0&lt;br /&gt;1 invokespecial #3 &lt;Method java.lang.Object()&gt;&lt;br /&gt;4 aload_0&lt;br /&gt;5 aload_1&lt;br /&gt;6 putfield #5 &lt;Field java.lang.String name&gt;&lt;br /&gt;9 aload_0&lt;br /&gt;10 iload_2&lt;br /&gt;11 putfield #4 &lt;Field int idNumber&gt;&lt;br /&gt;14 aload_0&lt;br /&gt;15 aload_1&lt;br /&gt;16 iload_2&lt;br /&gt;17 invokespecial #6 &lt;Method void storeData(java.lang.String, int)&gt;&lt;br /&gt;20 return&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first opcode instruction at location 0, aload_0, pushes the this reference onto the operand stack. (Remember, the first entry of the local variable table for instance methods and constructors is the this reference.) &lt;br /&gt;&lt;br /&gt;The next opcode instruction at location 1, invokespecial, calls the constructor of this class's superclass. Because all classes that do not explicitly extend any other class implicitly inherit from java.lang.Object , the compiler provides the necessary bytecode to invoke this base class constructor. During this opcode, the top value from the operand stack, this, is popped.&lt;br /&gt;&lt;br /&gt;The next two opcodes, at locations 4 and 5 push the first two entries from the local variable table onto the operand stack. The first value to be pushed is the this reference. The second value is the first formal parameter to the constructor, strName . These values are pushed in preparation for the putfield opcode instruction at location 6. &lt;br /&gt;&lt;br /&gt;The putfield opcode pops the two top values off the stack and stores a reference to strName into the instance data name of the object referenced by this . &lt;br /&gt;&lt;br /&gt;The next three opcode instructions at locations 9, 10, and 11 perform the same operation with the second formal parameter to the constructor, num , and the instance variable, idNumber . &lt;br /&gt;&lt;br /&gt;The next three opcode instructions at locations 14, 15, and 16 prepare the stack for the storeData method call. These instructions push the this reference, strName , and num , respectively. The this reference must be pushed because an instance method is being called. If the method was declared static, the this reference would not need to be pushed. The strName and num values are pushed since they are the parameters to the storeData method. When the storeData method executes, the this reference, strName , and num , will occupy indexes 0, 1, and 2, respectively, of the local variable table contained in the frame for that method. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Compiler options&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The javac compiler provides a few options that you need to know. The first is the -O option. The JDK documentation claims that -O will optimize your code for execution speed. Using -O with the javac compiler with the Sun Java 2 SDK has no effect on the generated code. Previous versions of the Sun javac compiler performed some rudimentary bytecode optimizations, but these have since been removed. The SDK documentation, however, has not been updated. The only reason -O remains as an option is for compatibility with older make files. Therefore, there is currently no reason to use it. &lt;br /&gt;&lt;br /&gt;This also means that the bytecode that is generated by the javac compiler is not any better than the code that you write. For example, if you write a loop that contains an invariant, the invariant will not be removed from the loop by the javac compiler. Programmers are used to compilers from other languages that clean up badly written code. Unfortunately, javac does not do this. More importantly, the javac compiler does not perform simple optimizations like loop unrolling, algebraic simplification, strength reduction, and others. To get these benefits and other simple optimizations, the programmer must perform them on the Java source code and not rely on the javac compiler to perform them. There are many techniques you can use to make the Java compiler generate faster and smaller bytecode. Unfortunately, until Java compilers perform them, you must implement them yourself to achieve their benefits. &lt;br /&gt;&lt;br /&gt;The javac compiler also supplies the -g and -g:none options. The -g option tells the compiler to generate all the debugging information. The -g:none option tells the compiler to generate no debugging information. Compiling with -g:none generates the smallest possible .class file. Therefore, this option should be used when trying to generate the smallest possible .class files prior to deployment. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Java debuggers&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;One very useful feature that I have yet to see in a Java debugger is a disassembly view similar to that of a C or C++ debugger. Disassembling Java code would reveal the bytecode, much like disassembling C or C++ code reveals assembler code. In addition to this feature, another useful feature could be the ability to single step through the bytecode, executing one opcode at a time. &lt;br /&gt;&lt;br /&gt;This level of functionality would allow the programmer to see, first hand, the bytecode generated by the Java compiler as well as step through it during debugging. The more information a programmer has about the code generated and executed, the better chance there is of avoiding problems. This type of debugger feature would also encourage programmers to look at, and understand, the bytecode that is executing for their source code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-530307989180428284?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/530307989180428284/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=530307989180428284' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/530307989180428284'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/530307989180428284'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/09/java-bytecode.html' title='Java bytecode:'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_h8w_fktOw40/RuaEHmAGlrI/AAAAAAAAAAY/0KDtIXu5NGY/s72-c/bytecode_1.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-1799256998734331829</id><published>2007-09-06T06:39:00.000-07:00</published><updated>2007-09-06T06:40:08.530-07:00</updated><title type='text'>Server-side web programming</title><content type='html'>Web applications are client/server applications. The web browser is the client. The server is a program running on some computer which is identified by a number called the port to distinguish it from other server programs. Clients access the server program via the pair (server,port) called a socket. The browser client (as well as other client programs) initiates the interaction with a URL request: &lt;br /&gt;protocol://data_source&lt;br /&gt;&lt;br /&gt;where the protocol is any number of possiblities, including http, file, https, ftp, etc. The data_source can be any number of things from a regular file on the client's machine to a file or program on some server such as these: &lt;br /&gt;file://file&lt;br /&gt;http://server/dir1/dir2/file&lt;br /&gt;http://server/dir1/program&lt;br /&gt;http://server:port/file       (server running on alternate port)&lt;br /&gt;&lt;br /&gt;The protocol normally dictates the port, but we can specify it if it's different than the usual one. If the target file is a directory, then a default file or program is chosen as the source. &lt;br /&gt;&lt;br /&gt;Server-side web programming means that an HTTP request from a browser causes the web server to run a program which generates HTML (or other data) and sends it back to the browser. Java uses Servlets and Java Server Pages (JSP) for server-side programming. These two software technologies are Java's contribution to the two primary styles of server-side programming: &lt;br /&gt;HTML code generated entirely by programming: Perl/CGI, Servlets &lt;br /&gt;program code embedded within HTML code: PHP, ASP, JSP &lt;br /&gt;Server-side programming stands in contrast to client-side programming which is usually equated with JavaScript, but can also be effected by Java Applets, Flash, or any others which provide a browser plugin. &lt;br /&gt;&lt;br /&gt;Tomcat web server&lt;br /&gt;A Java Servlet is an object that can the executed by an HTTP server due to the invocation of a browser client. This ability is not automatically part of standard web servers like Apache and Microsoft's IIS so we need a specialized web server for that purpose. The Apache open source tomcat web server serves our needs; its website is this: &lt;br /&gt;http://tomcat.apache.org/ &lt;br /&gt;In order to permit user access and not to conflict with other web services — the standard web service runs on port 80, a restricted port in UNIX system — tomcat runs on the standard port 8080. The Tomcat web server starts a Java virtual machine (JVM) and handles browser client accesses by executing the servlets in threads created by this JVM which makes the entire web service process very fast, in contrast, say to CGI programming in which each web server activation requires a new process creation. &lt;br /&gt;Eclipse Web applications setup&lt;br /&gt;The Eclipse IDE supports many plugin tools and allows developers to directly create and modify plugins. It's not clear at this stage of development what will be the definitive plugin tool for web development but the so-called webtools development packages found at &lt;br /&gt;http://www.eclipse.org/webtools/ &lt;br /&gt;seems like a likely contender. We'll use the webtools current release build, version R-1.5.2-200610261841, which requires eclipse version 3.1.1. The current stable webtools release is 1.5M4, but this requires eclipse version 3.2M4. &lt;br /&gt;&lt;br /&gt;The eclipse webtools and support plugins you'll need are these: &lt;br /&gt;wtp-sdk-R-1.5.2-200610261841.zip &lt;br /&gt;emf-sdo-xsd-SDK-2.2.1.zip &lt;br /&gt;GEF-SDK-3.2.1.zip &lt;br /&gt;JEM-SDK-1.2.1.zip &lt;br /&gt;&lt;br /&gt;The Apache tomcat web server, currently version 6.0.14, uses this distribution file, also available through the tomcat website: &lt;br /&gt;apache-tomcat-6.0.14.zip&lt;br /&gt;&lt;br /&gt;Install Webtools&lt;br /&gt;Assuming that eclipse 3.1.1 is installed as the directory "eclipse", extract these zip archives: &lt;br /&gt;wtp-sdk-R-1.5.2-200610261841.zip &lt;br /&gt;emf-sdo-xsd-SDK-2.2.1.zip &lt;br /&gt;GEF-SDK-3.2.1.zip &lt;br /&gt;JEM-SDK-1.2.1.zip &lt;br /&gt;&lt;br /&gt;into the directory containing the eclipse subdirectory (e.g., the C:\ directory in my suggested Windows installation of Eclipse). These zip archives already have eclipse as their top-level directory, and so their contents will be extracted correctly into the eclipse subdirectory. &lt;br /&gt;&lt;br /&gt;The zip files extract almost entirely into the features and plugins subdirectories of eclipse. The EMF zip archive contains duplicates of the top-level files epl-v10.html and notice.html You can either let them be overwritten or not — it is unimportant. &lt;br /&gt;Install Tomcat&lt;br /&gt;Unzip the file apache-tomcat-6.0.14.zip into your folder of choice; it creates the subdirectory &lt;br /&gt;apache-tomcat-6.0.14&lt;br /&gt;A good choice for location might be the same directory holding eclipse. &lt;br /&gt;Tomcat Server Setup in Eclipse&lt;br /&gt;Open Eclipse and select New  Other. You should see quite a number of new categories now available due to the plugin additions. &lt;br /&gt;&lt;br /&gt;To create the Tomcat server: &lt;br /&gt;Open the Server category, select the Server entry within and click Next. &lt;br /&gt;In the Define a New Server window, select Apache  Tomcat v5.5 Server, click Next. &lt;br /&gt;In the Tomcat Server window, click the Browse button to specify the Tomcat installation directory, apache-tomcat-6.0.14. Click Finish. &lt;br /&gt;Specify the web browser to use&lt;br /&gt;Eclipse has its own internal web browser that can be used to display web content, but you may want to use an external web browser. In eclipse, select: &lt;br /&gt;Window  Preferences  General  Web Browser &lt;br /&gt;It's not clear that the so-called Default System Web Browser will find the right thing. You can add your own external browser if necessary. On a Windows installation, Internet Explorer will be among the list of browsers; you can simply select it, it takes no parameters. &lt;br /&gt;&lt;br /&gt;For other browsers, e.g., firefox or mozilla browsers, if already on the list, select it, click Edit, and set the parameters to &lt;br /&gt;-url %URL%&lt;br /&gt;&lt;br /&gt;If not in the list, click New, fill in the Name (e.g., "Firefox"); browse to find the location of the executable and finally set the parameters as above. &lt;br /&gt;The structure of a Servlet&lt;br /&gt;The activation of a servlet is initiated by a client-side (browser) request. There are two types of requests: GET and POST. GET requests are most standard and always activated by typing any URL into a browser. GET requests are also those in which you see parameters delivered in the URL itself after the "?" character, a portion called the query string. POST requests are less frequent and are normally initiated by HTML forms. &lt;br /&gt;&lt;br /&gt;A Java Servlet is an extension of the javax.servlet.http.HttpServlet. A GET or POST request activates one of the two built-in functions: doGet or doPost, respectively. Many server-side programs do not need to differentiate between these two activations and it is often common to merge the behaviors of these activations. &lt;br /&gt;Servlet template&lt;br /&gt;import java.io.*;             // for PrintWriter, IOException&lt;br /&gt;import javax.servlet.*;       // for Servlet*&lt;br /&gt;import javax.servlet.http.*;  // for HttpServlet*&lt;br /&gt;&lt;br /&gt;public class MyServlet extends HttpServlet implements Servlet&lt;br /&gt;{&lt;br /&gt;  protected void &lt;br /&gt;    doGet(HttpServletRequest request, HttpServletResponse response)&lt;br /&gt;  throws ServletException, IOException {&lt;br /&gt;    /* ... */&lt;br /&gt;  }&lt;br /&gt;    &lt;br /&gt;  protected void &lt;br /&gt;    doPost(HttpServletRequest request, HttpServletResponse response)&lt;br /&gt;  throws ServletException, IOException { &lt;br /&gt;    /* ... */&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Typical content for the doGet or doPost function is as follows: &lt;br /&gt;response.setContentType("text/html");&lt;br /&gt;PrintWriter out = response.getWriter();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-1799256998734331829?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/1799256998734331829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=1799256998734331829' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1799256998734331829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1799256998734331829'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/09/server-side-web-programming.html' title='Server-side web programming'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-3486995591671158973</id><published>2007-09-02T04:11:00.000-07:00</published><updated>2007-09-02T04:15:28.325-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hibernate tutorial examples'/><title type='text'>Hibernate</title><content type='html'>&lt;b&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;What is Hibernate?&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;Hibernate 3.0, the latest Open Source persistence technology at the heart of J2EE EJB 3.0 is available for download from &lt;a href="http://www.hibernate.org/Download/DownloadOverview" target="_blank"&gt;Hibernet.org&lt;/a&gt;.The Hibernate 3.0 core is 68,549 lines of Java code together with 27,948 lines of unit tests, all freely available under the LGPL, and has been in development for well over a year. Hibernate maps the Java classes to the database tables. It also provides the data query and retrieval facilities that significantly reduces the development time.  Hibernate is not the best solutions for data centric applications that only uses the stored-procedures to implement the business logic in database. It is most useful with object-oriented domain modes and business logic in the Java-based middle-tier. Hibernate allows transparent persistence that enables the applications to switch any database. Hibernate can be used in Java Swing applications, Java Servlet-based applications, or J2EE applications using EJB session beans. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Features of Hibernate&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Hibernate 3.0 provides      three full-featured query facilities: &lt;b&gt;Hibernate Query Language&lt;/b&gt;, the      newly enhanced &lt;b&gt;Hibernate Criteria Query API&lt;/b&gt;, and enhanced support      for queries expressed in the &lt;b&gt;native SQL &lt;/b&gt;dialect of the database.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Filters for working with      temporal (historical), regional or permissioned data.&lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Enhanced Criteria query      API: with full support for projection/aggregation and subselects.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Runtime performance      monitoring: via JMX or local Java API, including a second-level cache      browser.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Eclipse support,      including a suite of Eclipse plug-ins for working with Hibernate 3.0,      including mapping editor, interactive query prototyping, schema reverse      engineering tool.&lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Hibernate is Free under      LGPL: Hibernate can be used to develop/package and distribute the      applications for free.&lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Hibernate is Scalable:      Hibernate is very performant and due to its dual-layer architecture can be      used in the clustered environments.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Less Development Time:      Hibernate reduces the development timings as it supports inheritance,      polymorphism, composition and the Java Collection framework.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Automatic Key      Generation: Hibernate supports the automatic generation of primary key for      your.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt; JDK 1.5      Enhancements: The new JDK has been released as a preview earlier this year      and we expect a slow migration to the new 1.5 platform throughout 2004.      While Hibernate3 still runs perfectly with JDK 1.2, Hibernate3 will make      use of some new JDK features. JSR 175 annotations, for example, are a      perfect fit for Hibernate metadata and we will embrace them aggressively.      We will also support Java generics, which basically boils down to allowing      type safe collections.&lt;br /&gt;       &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;EJB3-style persistence      operations: EJB3 defines the &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;create()&lt;/span&gt;&lt;/tt&gt;      and &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;merge()&lt;/span&gt;&lt;/tt&gt; operations,      which are slightly different to Hibernate's &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;saveOrUpdate()&lt;/span&gt;&lt;/tt&gt; and &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;saveOrUpdateCopy()&lt;/span&gt;&lt;/tt&gt;      operations. Hibernate3 will support all four operations as methods of the &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;Session&lt;/span&gt;&lt;/tt&gt; interface.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Hibernate XML binding      enables data to be represented as XML and POJOs interchangeably.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;The EJB3 draft      specification support for POJO persistence and annotations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;In this lesson you will learn the architecture of Hibernate.  The following diagram describes the high level architecture of hibernate:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;  &lt;v:stroke joinstyle="miter"&gt;  &lt;v:formulas&gt;   &lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;   &lt;v:f eqn="sum @0 1 0"&gt;   &lt;v:f eqn="sum 0 0 @1"&gt;   &lt;v:f eqn="prod @2 1 2"&gt;   &lt;v:f eqn="prod @3 21600 pixelWidth"&gt;   &lt;v:f eqn="prod @3 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @0 0 1"&gt;   &lt;v:f eqn="prod @6 1 2"&gt;   &lt;v:f eqn="prod @7 21600 pixelWidth"&gt;   &lt;v:f eqn="sum @8 21600 0"&gt;   &lt;v:f eqn="prod @7 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @10 21600 0"&gt;  &lt;/v:formulas&gt;  &lt;v:path extrusionok="f" gradientshapeok="t" connecttype="rect"&gt;  &lt;o:lock ext="edit" aspectratio="t"&gt; &lt;/v:shapetype&gt;&lt;v:shape id="_x0000_i1025" type="#_x0000_t75" alt="" style="'width:281.25pt;"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\INNOVE~1\LOCALS~1\Temp\msohtml1\01\clip_image001.gif" href="http://www.roseindia.net/hibernate/hibernatearchitecture.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/INNOVE%7E1/LOCALS%7E1/Temp/msohtml1/01/clip_image001.gif" shapes="_x0000_i1025" border="0" height="375" width="375" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;The above diagram shows that Hibernate is using the database and configuration data to provide persistence services (and persistent objects) to the application.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;span style="color: navy;"&gt;To use Hibernate, it is required to create Java classes that represents the table in the database and then map the instance variable in the class with the columns in the database. Then Hibernate can be used to perform operations on the database like select, insert, update and delete the records in the table. Hibernate automatically creates the query to perform these operations. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Hibernate architecture has three main components:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size: 10pt; font-family: Symbol; color: navy;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Connection Management&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Hibernate Connection management service provide efficient management of the database connections. Database connection is the most expensive part of interacting with the database as it requires a lot of resources of open and close the database connection.&lt;br /&gt;   &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size: 10pt; font-family: Symbol; color: navy;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Transaction management:&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Transaction management service provide the ability to the user to execute more than one database statements at a time.&lt;br /&gt;   &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size: 10pt; font-family: Symbol; color: navy;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Object relational mapping:&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Object relational mapping is technique of mapping the data representation from an object model to a relational data model. This part of the hibernate is used to select, insert, update and delete the records form the underlying table. When we pass an object to a &lt;b&gt;Session.save()&lt;/b&gt; method, Hibernate reads the state of the variables of that object and executes the necessary query. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Hibernate is very good tool as far as object relational mapping is concern, but in terms of connection management and transaction management, it is lacking in performance and capabilities. So usually hibernate is being used with other connection management and transaction management tools. For example apache DBCP is used for connection pooling with the Hibernate.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Hibernate provides a lot of flexibility in use. It is called "&lt;b&gt;Lite&lt;/b&gt;" architecture when we only uses the object relational mapping component. While in "&lt;b&gt;Full Cream&lt;/b&gt;" architecture all the three component Object Relational mapping, Connection Management and Transaction Management) are used.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;In this section I will show you how to create a simple program to insert record in MySQL database. You can run this program from Eclipse or from command prompt as well. I am assuming that you are familiar with MySQL and Eclipse environment.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Configuring Hibernate&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;In this application Hibernate provided connection pooling and transaction management is used for simplicity. Hibernate uses the hibernate.cfg.xml to create the connection pool and setup required environment.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="color: navy;"&gt;Here is the code:&lt;/span&gt;&lt;/strong&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; width: 478.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0" width="638"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 475.5pt;" width="634"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: black;"&gt;&lt;?xml version='1.0'   encoding='utf-8'?&gt;&lt;br /&gt;  &lt;!DOCTYPE hibernate-configuration PUBLIC&lt;br /&gt;  "-//Hibernate/Hibernate Configuration DTD//EN"&lt;br /&gt;  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;hibernate-configuration&gt;&lt;br /&gt;  &lt;session-factory&gt;&lt;br /&gt;        &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;&lt;br /&gt;        &lt;property name="hibernate.connection.url"&gt;&lt;b&gt;jdbc:mysql://localhost/hibernatetutorial&lt;/b&gt;&lt;/property&gt;&lt;br /&gt;        &lt;property name="hibernate.connection.username"&gt;&lt;b&gt;root&lt;/b&gt;&lt;/property&gt;&lt;br /&gt;        &lt;property name="hibernate.connection.password"&gt;&lt;/property&gt;&lt;br /&gt;        &lt;property name="hibernate.connection.pool_size"&gt;10&lt;/property&gt;&lt;br /&gt;        &lt;property name="show_sql"&gt;&lt;b&gt;true&lt;/b&gt;&lt;/property&gt;&lt;br /&gt;        &lt;property name="dialect"&gt;&lt;b&gt;org.hibernate.dialect.MySQLDialect&lt;/b&gt;&lt;/property&gt;&lt;br /&gt;        &lt;property name="hibernate.hbm2ddl.auto"&gt;&lt;b&gt;update&lt;/b&gt;&lt;/property&gt;&lt;br /&gt;        &lt;!-- Mapping files --&gt;&lt;br /&gt;        &lt;mapping resource=""&gt;contact.hbm.xml&lt;/b&gt;"/&gt;&lt;br /&gt;  &lt;/session-factory&gt;&lt;br /&gt;  &lt;/hibernate-configuration&gt;&lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;In the above configuration file we specified to use the "&lt;b&gt;hibernatetutorial"&lt;/b&gt; which is running on &lt;b&gt;localhost&lt;/b&gt; and the user of the database is root with no password. The &lt;b&gt;dialect&lt;/b&gt; property  is &lt;b&gt;org.hibernate.dialect.MySQLDialect&lt;/b&gt; which tells the Hibernate that we are using MySQL Database. Hibernate supports many database. With the use of the &lt;a href="http://www.hibernate.org/" target="_blank" title="Visit page outside Confluence"&gt;Hibernate&lt;/a&gt; (Object/Relational Mapping and Transparent Object Persistence for Java and SQL Databases),  we can use the following databases dialect type property:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;DB2 - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.DB2Dialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;HypersonicSQL - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.HSQLDialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Informix - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.InformixDialect&lt;/span&gt;&lt;/tt&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Ingres - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.IngresDialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Interbase - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.InterbaseDialect&lt;/span&gt;&lt;/tt&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Pointbase - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.PointbaseDialect&lt;/span&gt;&lt;/tt&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;PostgreSQL - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/span&gt;&lt;/tt&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Mckoi SQL - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.MckoiDialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Microsoft SQL Server - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.SQLServerDialect&lt;/span&gt;&lt;/tt&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;MySQL - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.MySQLDialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Oracle (any version) - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.OracleDialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Oracle 9 - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.Oracle9Dialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Progress - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.ProgressDialect&lt;/span&gt;&lt;/tt&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;FrontBase - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.FrontbaseDialect&lt;/span&gt;&lt;/tt&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;SAP DB - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.SAPDBDialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Sybase - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.SybaseDialect&lt;/span&gt;&lt;/tt&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Sybase Anywhere - &lt;tt&gt;&lt;span style="font-size: 10pt;"&gt;org.hibernate.dialect.SybaseAnywhereDialect&lt;/span&gt;&lt;/tt&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;The &lt;mapping resource=""&gt;contact.hbm.xml&lt;/b&gt;"/&gt; property is the mapping for our contact table. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Writing First Persistence Class&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Hibernate uses the Plain Old Java Objects (POJOs) classes to map to the database table. We can configure the variables to map to the database column. Here is the code for Contact.java:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; width: 391.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0" width="522"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 2.25pt; width: 384pt;" nowrap="nowrap" valign="top" width="512"&gt;   &lt;p class="MsoNormal"&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;package &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;roseindia.tutorial.hibernate;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@author &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;Deepak Kumar&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* Java Class to map to the datbase Contact Table&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public class &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;Contact {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;private &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;String firstName;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;private &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;String lastName;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;private &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;String email;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;private long &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;id;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@return &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;Email&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;String getEmail() {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;return &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;email;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@return &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;First Name&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;String getFirstName() {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;return &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;firstName;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/** &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@return &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;Last name&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;String getLastName() {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;return &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;lastName;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@param &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;string Sets the Email&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public void &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;setEmail(String string) {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;email = string;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@param &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;string Sets the First Name&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public void &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;setFirstName(String string) {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;firstName = string;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@param &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;string sets the Last Name&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public void &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;setLastName(String string) {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;lastName = string;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@return &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;ID Returns ID&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public long &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;getId() {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;return &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;id;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@param &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;l Sets the ID&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public void &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;setId(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;long &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;l) {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;id = l;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Mapping the Contact Object to the Database Contact table&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;The file contact.hbm.xml is used to map Contact Object to the Contact table in the database. Here is the code for contact.hbm.xml:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; width: 478.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0" width="638"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 475.5pt;" width="634"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: black;"&gt;&lt;?xml   version="1.0"?&gt;&lt;br /&gt;  &lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"&lt;br /&gt;  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;hibernate-mapping&gt;&lt;br /&gt;    &lt;class name="roseindia.tutorial.hibernate.Contact" table="CONTACT"&gt;&lt;br /&gt;     &lt;id name="id" type="long" column="ID"&gt;&lt;br /&gt;     &lt;generator class="assigned"&gt;&lt;br /&gt;    &lt;/id&gt;&lt;br /&gt; &lt;br /&gt;    &lt;property name="firstName"&gt;&lt;br /&gt;       &lt;column name="FIRSTNAME"&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;    &lt;property name="lastName"&gt;&lt;br /&gt;      &lt;column name="LASTNAME"&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;    &lt;property name="email"&gt;&lt;br /&gt;      &lt;column name="EMAIL"&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;   &lt;/class&gt;&lt;br /&gt;  &lt;/hibernate-mapping&gt;&lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Setting Up MySQL Database&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;In the configuration file(hibernate.cfg.xml) we have specified to use &lt;b&gt;hibernatetutorial&lt;/b&gt; database running on localhost.  So, create the databse ("&lt;b&gt;hibernatetutorial") &lt;/b&gt;on the MySQL server running on localhost. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Developing Code to Test Hibernate example&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Now we are ready to write a program to insert the data into database. We should first understand about the Hibernate's Session. Hibernate Session is the main runtime interface between a Java application and Hibernate. First we are required to get the Hibernate Session.SessionFactory allows application to create the Hibernate Sesssion by reading the configuration from hibernate.cfg.xml file.  Then the save method on session object is used to save the contact information to the database:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;session.save(contact)&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Here is the code of FirstExample.java&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; width: 300pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0" width="400"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 2.25pt;" nowrap="nowrap" valign="top"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;package &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;roseindia.tutorial.hibernate;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;org.hibernate.Session;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;org.hibernate.SessionFactory;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;org.hibernate.cfg.Configuration;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(127, 159, 191);"&gt;@author &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;Deepak Kumar&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* http://www.roseindia.net&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;* Hibernate example to inset data into Contact table&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt; &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public class &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;FirstExample {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;public static void &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;main(String[] args) {&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;Session session = &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;null&lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;try&lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;{&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;      &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 127, 95);"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for use&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;      &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;SessionFactory sessionFactory = &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;new &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;Configuration().configure().buildSessionFactory();&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;       &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;session =sessionFactory.openSession();&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;        &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 127, 95);"&gt;//Create new instance of Contact and set values in it by reading them from form object&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;         &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;System.out.println(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(42, 0, 255);"&gt;"Inserting Record"&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;);&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;        &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;Contact contact = &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;new &lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;Contact();&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;        &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;contact.setId(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(153, 0, 0);"&gt;3&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;);&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;        &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;contact.setFirstName(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(42, 0, 255);"&gt;"Deepak"&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;);&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;        &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;contact.setLastName(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(42, 0, 255);"&gt;"Kumar"&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;);&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;        &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;contact.setEmail(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(42, 0, 255);"&gt;"deepak_38@yahoo.com"&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;);&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;        &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;session.save(contact);&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;        &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;System.out.println(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(42, 0, 255);"&gt;"Done"&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;);&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;(Exception e){&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;      &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;System.out.println(e.getMessage());&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; color: rgb(127, 0, 85);"&gt;finally&lt;/span&gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;{&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;      &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: rgb(63, 127, 95);"&gt;// Actual contact insertion will happen at this step&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;      &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;session.flush();&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;      &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;session.close();&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;      &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;    &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: white;"&gt;  &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black;"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;In the next section I will show how to run and test the program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Hibernate is free open source software it can be download from &lt;a href="http://www.hibernate.org/6.html"&gt;http://www.hibernate.org/6.html&lt;/a&gt;. Visit the site and download Hibernate 3.0. You can download the Hibernate and install it yourself. But I have provided very thing in one zip file. Download the example code and library from &lt;a href="http://www.roseindia.net/hibernate/hibernate.zip"&gt;here&lt;/a&gt; and extract the content in your favorite directory say "C:\hibernateexample". Download file contains the Eclipse project. To run the example you should have the Eclipse IDE on your machine. Start the Eclipse project and select Java Project as shown below. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1026" type="#_x0000_t75" alt="" style="'width:377.25pt;height:377.25pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\INNOVE~1\LOCALS~1\Temp\msohtml1\01\clip_image002.gif" href="http://www.roseindia.net/hibernate/newproj.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/INNOVE%7E1/LOCALS%7E1/Temp/msohtml1/01/clip_image002.gif" shapes="_x0000_i1026" border="0" height="503" width="503" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Click on "Next" button. In the new screen, enter "hibernateexample" as project name and browse the extracted directory "C:\hibernateexample". &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1027" type="#_x0000_t75" alt="" style="'width:375.75pt;height:374.25pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\INNOVE~1\LOCALS~1\Temp\msohtml1\01\clip_image003.gif" href="http://www.roseindia.net/hibernate/hibernateexample.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/INNOVE%7E1/LOCALS%7E1/Temp/msohtml1/01/clip_image003.gif" shapes="_x0000_i1027" border="0" height="499" width="501" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Click on "Next" button. In the next screen leave the output folder as default "hibernateexample/bin" .&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1028" type="#_x0000_t75" alt="" style="'width:377.25pt;height:374.25pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\INNOVE~1\LOCALS~1\Temp\msohtml1\01\clip_image004.gif" href="http://www.roseindia.net/hibernate/outputfolder.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/INNOVE%7E1/LOCALS%7E1/Temp/msohtml1/01/clip_image004.gif" shapes="_x0000_i1028" border="0" height="499" width="503" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Click on the "Finish" button.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Now Open the FirstExample.java in the editor as show below.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1029" type="#_x0000_t75" alt="" style="'width:375pt;height:112.5pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\INNOVE~1\LOCALS~1\Temp\msohtml1\01\clip_image005.jpg" href="http://www.roseindia.net/hibernate/openexample.jpg"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/INNOVE%7E1/LOCALS%7E1/Temp/msohtml1/01/clip_image006.jpg" shapes="_x0000_i1029" border="0" height="150" width="500" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Copy  contact.hbm.xml, and hibernate.cfg.xml in the bin directory of the project using windows explorer. To run the example select Run-&gt; Run As -&gt; Java Application from the menu bar as shown below.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1030" type="#_x0000_t75" alt="" style="'width:344.25pt;height:271.5pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\INNOVE~1\LOCALS~1\Temp\msohtml1\01\clip_image007.gif" href="http://www.roseindia.net/hibernate/run.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/INNOVE%7E1/LOCALS%7E1/Temp/msohtml1/01/clip_image007.gif" shapes="_x0000_i1030" border="0" height="362" width="459" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;This will run the Hibernate example program in Eclipse following output will displayed on the Eclipse Console.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1031" type="#_x0000_t75" alt="" style="'width:517.5pt;height:117pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\INNOVE~1\LOCALS~1\Temp\msohtml1\01\clip_image008.gif" href="http://www.roseindia.net/hibernate/output.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/INNOVE%7E1/LOCALS%7E1/Temp/msohtml1/01/clip_image008.gif" shapes="_x0000_i1031" border="0" height="156" width="690" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;In this section I showed you how to run the our first Hibernate 3.0 example.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;In the last example we created contact.hbm.xml to map Contact Object to the Contact table in the database. Now let's understand the each component of the mapping file.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;To recall here is the content of contact.hbm.xml:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; width: 478.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0" width="638"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 475.5pt;" width="634"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: black;"&gt;&lt;?xml   version="1.0"?&gt;&lt;br /&gt;  &lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"&lt;br /&gt;  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;hibernate-mapping&gt;&lt;br /&gt;    &lt;class name="roseindia.tutorial.hibernate.Contact" table="CONTACT"&gt;&lt;br /&gt;     &lt;id name="id" type="long" column="ID"&gt;&lt;br /&gt;     &lt;generator class="assigned"&gt;&lt;br /&gt;    &lt;/id&gt;&lt;br /&gt; &lt;br /&gt;    &lt;property name="firstName"&gt;&lt;br /&gt;       &lt;column name="FIRSTNAME"&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;    &lt;property name="lastName"&gt;&lt;br /&gt;      &lt;column name="LASTNAME"&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;    &lt;property name="email"&gt;&lt;br /&gt;      &lt;column name="EMAIL"&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;   &lt;/class&gt;&lt;br /&gt;  &lt;/hibernate-mapping&gt;&lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;Hibernate mapping documents are simple xml documents. Here are important elements of the mapping file:.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ol start="1" type="1"&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;hibernate-mapping&gt;      element&lt;/b&gt;&lt;br /&gt;     The first or root element of hibernate mapping document is &lt;hibernate-mapping&gt;      element. Between the &lt;&lt;b&gt;hibernate-mapping&gt;&lt;/b&gt; tag class element(s)      are present.&lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt; &lt;class&gt;      element&lt;/b&gt;&lt;br /&gt;     The &lt;class&gt; element maps the class object with corresponding entity      in the database. It also tells what table in the database has to access      and what column in that table it should use. Within one      &lt;hibernate-mapping&gt; element, several &lt;class&gt; mappings are      possible.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt; &lt;id&gt;      element&lt;/b&gt;&lt;br /&gt;     The &lt;id&gt; element in unique identifier to identify and object. In      fact &lt;id&gt; element map with the primary key of the table. In our code      :&lt;br /&gt;     &lt;span style="color: blue;"&gt;&lt;id name="id" type="long" column="ID"&gt;&lt;br /&gt;     &lt;/span&gt;primary key maps to the &lt;b&gt;ID&lt;/b&gt; field of the table &lt;b&gt;CONTACT&lt;/b&gt;.      The attributes of the &lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;id&lt;/span&gt; element are: &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;name: &lt;/b&gt;The       property name used by the persistent class. &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;column:&lt;/b&gt; The       column used to store the primary key value. &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;type:&lt;/b&gt; The Java       data type used. &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;unsaved-value:&lt;/b&gt;       This is the value used to determine if a class has been made persistent.       If the value of the id attribute is null, then it means that this object       has not been persisted.&lt;br /&gt;           &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;generator&gt;      element&lt;/b&gt;&lt;br /&gt;     The &lt;b&gt;&lt;generator&gt; &lt;/b&gt;method&lt;b&gt; &lt;/b&gt;is used to generate the primary      key for the new record. Here is some of the commonly used generators :&lt;br /&gt;       &lt;br /&gt;     &lt;b&gt;*&lt;/b&gt; &lt;b&gt;Increment &lt;/b&gt;- This is used to generate primary keys of type      long, short or int that are unique only. It should not be used in the clustered      deployment environment.&lt;br /&gt;       &lt;br /&gt;     &lt;b&gt;*  Sequence&lt;/b&gt; - Hibernate can also use the sequences to generate      the primary key. It can be used with DB2, PostgreSQL, Oracle, SAP DB      databases.&lt;br /&gt;      &lt;br /&gt;     &lt;b&gt;* Assigned&lt;/b&gt; - Assigned method is used when application code      generates the primary key.&lt;br /&gt;       &lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;property&gt;      element&lt;/b&gt;&lt;br /&gt;     The &lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;property&lt;/span&gt; elements define standard Java attributes      and their mapping into database schema. The &lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;property&lt;/span&gt;      element supports the &lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;column&lt;/span&gt; child element to specify      additional properties, such as the index name on a column or a specific      column type. &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ol&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;In this lesson you will learn about hibernate &lt;generator&gt; method in detail. Hibernate generator element generates the primary key for new record. There are many options provided by the generator method to be used in different situations. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;The &lt;generator&gt; element&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;This is the optional element under &lt;id&gt; element. The &lt;generator&gt; element is used to specify the class name to be used to generate the primary key for new record while saving a new record. The &lt;param&gt; element is used to pass the parameter (s) to the  class. Here is the example of generator element from our first application:&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;&lt;generator class="assigned"&gt;&lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;In this case &lt;generator&gt; element do not generate the primary key and it is required to set the primary key value before calling save() method.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Here are the list of some commonly used generators in hibernate: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 204) none repeat scroll 0% 50%; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0" width="80%"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0in; background: rgb(255, 255, 153) none repeat scroll 0% 50%; width: 16%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Generator&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; background: rgb(255, 255, 153) none repeat scroll 0% 50%; width: 84%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Description&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;increment&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;It generates identifiers of type   long, short or int that are unique only when no other process is inserting   data into the same table. It should not the used in the clustered   environment.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;identity&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;It supports identity columns in   DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier   is of type long, short or int.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;sequence&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;The sequence generator uses a   sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in   Interbase. The returned identifier is of type long, short or int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;st1:city&gt;&lt;st1:place&gt;&lt;span style="color: navy;"&gt;hilo&lt;/span&gt;&lt;/st1:place&gt;&lt;/st1:City&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;The &lt;/span&gt;&lt;st1:city&gt;&lt;st1:place&gt;&lt;span style="color: navy;"&gt;hilo&lt;/span&gt;&lt;/st1:place&gt;&lt;/st1:City&gt;&lt;span style="color: navy;"&gt; generator uses a hi/lo algorithm to efficiently generate   identifiers of type long, short or int, given a table and column (by default   hibernate_unique_key and next_hi respectively) as a source of hi values. The   hi/lo algorithm generates identifiers that are unique only for a particular   database. Do not use this generator with connections enlisted with JTA or   with a user-supplied connection.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;seqhilo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;The seqhilo generator uses a   hi/lo algorithm to efficiently generate identifiers of type long, short or   int, given a named database sequence.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;uuid&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;The uuid generator uses a 128-bit   UUID algorithm to generate identifiers of type string, unique within a   network (the IP address is used). The UUID is encoded as a string of   hexadecimal digits of length 32.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;guid&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;It uses a database-generated GUID   string on MS SQL Server and MySQL.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;native&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;It picks identity, sequence or &lt;/span&gt;&lt;st1:city&gt;&lt;st1:place&gt;&lt;span style="color: navy;"&gt;hilo&lt;/span&gt;&lt;/st1:place&gt;&lt;/st1:City&gt;&lt;span style="color: navy;"&gt; depending upon the capabilities of the underlying   database.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;assigned&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;lets the application to assign an   identifier to the object before save() is called. This is the default   strategy if no &lt;generator&gt; element is specified.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;select&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;retrieves a primary key assigned   by a database trigger by selecting the row by some unique key and retrieving   the primary key value.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 16%;" width="16%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;foreign&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0in; width: 84%;" width="84%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;uses the identifier of another   associated object. Usually used in conjunction with a &lt;one-to-one&gt;   primary key association.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;As we have seen in the last section that the increment class generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. In this lesson I will show you how to write running program to demonstrate it. You should not use this method to generate the primary key in case of clustured environment.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;In this we will create a new table in database, add mappings in the contact.hbm.xml file, develop the POJO class (Book.java), write the program to test it out.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Create Table in the mysql database:&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;User the following sql statement to create a new table in the database.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue;"&gt; CREATE TABLE `book` (&lt;br /&gt;`id` int(11) NOT NULL default '0',&lt;br /&gt;`bookname` varchar(50) default NULL,&lt;br /&gt;PRIMARY KEY (`id`)&lt;br /&gt;) TYPE=MyISAM &lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Developing POJO Class (Book.java)&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Book.java is our POJO class which is to be persisted to the database table "book". &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 2.25pt;" nowrap="nowrap" valign="top"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 159, 191);"&gt;@author &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;Deepak Kumar&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* http://www.roseindia.net&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* Java Class to map to the database Book table&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;package &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;roseindia.tutorial.hibernate;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public class &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Book {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;private long &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;lngBookId;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;private &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;String strBookName;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 159, 191);"&gt;@return &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;Returns the lngBookId.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public long &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;getLngBookId() {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;return &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;lngBookId;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 159, 191);"&gt;@param &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;lngBookId The lngBookId to set.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public void &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;setLngBookId(&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;long &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;lngBookId) {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.lngBookId = lngBookId;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 159, 191);"&gt;@return &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;Returns the strBookName.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;String getStrBookName() {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;return &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;strBookName;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 159, 191);"&gt;@param &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;strBookName The strBookName to set.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public void &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;setStrBookName(String strBookName) {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.strBookName = strBookName;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Adding Mapping entries to contact.hbm.xml&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Add the following mapping code into the contact.hbm.xml file&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0" width="80%"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 100%;" width="100%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;&lt;script type="text/javascript"&gt; &lt;!-- google_ad_client = "pub-0714075272818912"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_ad_type = "text_image"; google_ad_channel =""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000080"; google_color_text = "000080"; google_color_url = "000080"; //--&gt;   &lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;   &lt;/script&gt;&lt;class name="roseindia.tutorial.hibernate.Book" table="book"&gt;&lt;br /&gt;       &lt;id name="lngBookId" type="long" column="id"&gt;&lt;br /&gt;          &lt;b&gt;&lt;generator class="increment"&gt;&lt;br /&gt;  &lt;/b&gt;     &lt;/id&gt;&lt;br /&gt; &lt;br /&gt;      &lt;property name="strBookName"&gt;&lt;br /&gt;           &lt;column name="bookname"&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;  &lt;/class&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt; Note that we have used &lt;b&gt;increment&lt;/b&gt; for the generator class. *&lt;/span&gt;&lt;span style="font-size: 10pt; color: navy;"&gt;After adding the entries to the xml file copy it to the bin directory of your hibernate eclipse project(this step is required if you are using eclipse).&lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Write the client program and test it out&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Here is the code of our client program to test the application.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 2.25pt;" nowrap="nowrap" valign="top"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 159, 191);"&gt;@author &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;Deepak Kumar&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* http://www.roseindia.net&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* Example to show the increment class of hibernate generator element to &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* automatically generate the primay key&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;package &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;roseindia.tutorial.hibernate;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//Hibernate Imports&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.Session;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.SessionFactory;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.cfg.Configuration;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public class &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;IdIncrementExample {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public static void &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;main(String[] args) {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Session session = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;null&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;try&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;{&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for use&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;SessionFactory sessionFactory = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Configuration().configure().buildSessionFactory();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;session =sessionFactory.openSession();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;       &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.Transaction tx = session.beginTransaction();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;       &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//Create new instance of Contact and set values in it by reading them from form object&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;       &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Inserting Book object into database.."&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Book book = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Book();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;book.setStrBookName(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Hibernate Tutorial"&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;session.save(book);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Book object persisted to the database."&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;          &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;tx.commit();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;          &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;session.flush();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;          &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;session.close();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;(Exception e){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(e.getMessage());&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;finally&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;{&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;To test the program Select Run-&gt;Run As -&gt; Java Application from the eclipse menu bar. This will create a new record into the book table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;In this tutorial we will show how to update a row with new information by retrieving data from the underlying database using the hibernate. Lets first write a java class to update a row to the database.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Create a java class:&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;Here is the code of our java file (&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;UpdateExample&lt;/span&gt;&lt;span style="color: navy;"&gt;.java), where we will update a field name "&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;InsuranceName"&lt;/span&gt;&lt;span style="color: navy;"&gt; with a value="&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;Jivan Dhara&lt;/span&gt;&lt;span style="color: navy;"&gt;" from a row of the insurance table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Here is the code of delete query: &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;UpdateExample .java &lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 204) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="0" cellpadding="0" cellspacing="0"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 2.25pt;" nowrap="nowrap" valign="top"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;package &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;roseindia.tutorial.hibernate;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;java.util.Date;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.Session;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.SessionFactory;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.Transaction;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.cfg.Configuration;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public class &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;UpdateExample {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 159, 191);"&gt;@param &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;args&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;   &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public static void &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;main(String[] args) {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;// TODO Auto-generated method stub&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Session sess = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;null&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;{&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;SessionFactory fact = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Configuration().configure().buildSessionFactory();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;sess = fact.openSession();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Transaction tr = sess.beginTransaction();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Insurance ins = (Insurance)sess.get(Insurance.class, &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Long(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(153, 0, 0);"&gt;1&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;));&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;ins.setInsuranceName(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Jivan Dhara"&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;ins.setInvestementAmount(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(153, 0, 0);"&gt;20000&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;ins.setInvestementDate(&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Date());&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;sess.update(ins);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;tr.commit();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;sess.close();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Update successfully!"&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;(Exception e){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(e.getMessage());&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;&lt;a href="http://www.roseindia.net/hibernate/UpdateExample.java"&gt;Download this code.&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Output:&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="width: 71%;" border="1" cellpadding="0" width="71%"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0.75pt; width: 100%;" width="100%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; color: red;"&gt;log4j:WARN No   appenders could be found for logger (org.hibernate.cfg.Environment). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; color: red;"&gt;log4j:WARN Please initialize the log4j   system properly.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; color: black;"&gt;Hibernate: select insurance0_.ID as   ID0_0_, insurance0_.insurance_name as insurance2_0_0_,   insurance0_.invested_amount as invested3_0_0_, insurance0_.investement_date   as investem4_0_0_ from insurance insurance0_ where insurance0_.ID=?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; color: black;"&gt;Hibernate: update insurance set   insurance_name=?, invested_amount=?, investement_date=? where ID=?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; color: black;"&gt;Update successfully!&lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;Hibernate Query Language or HQL for short is extremely powerful query language. HQL is much like SQL  and are case-insensitive, except for the names of the Java Classes and properties. Hibernate Query Language is used to execute queries against database. Hibernate automatically generates the sql query and execute it against underlying database if HQL is used in the application. HQL is based on the relational object models and makes the SQL object oriented. Hibernate Query Language uses Classes and properties instead of tables and columns. Hibernate Query Language is extremely powerful and it supports Polymorphism, Associations, Much less verbose than SQL.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;There are other options that can be used while using Hibernate. These are &lt;b&gt;Query By Criteria (QBC)&lt;/b&gt; and &lt;b&gt;Query BY Example (QBE) &lt;/b&gt;using Criteria API and the &lt;b&gt;Native SQL&lt;/b&gt; queries. In this lesson we will understand HQL in detail. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Why to use HQL?&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;Full support for      relational operations: &lt;/b&gt;HQL allows representing SQL queries in the form      of objects. Hibernate Query Language uses Classes and properties instead      of tables and columns.&lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;Return result as      Object: &lt;/b&gt;The HQL queries return the query result(s) in the form of      object(s), which is easy to use. This elemenates the need of creating the      object and populate the data from result set.&lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;Polymorphic Queries:&lt;/b&gt;      HQL fully supports &lt;b&gt;polymorphic queries&lt;/b&gt;. Polymorphic queries results      the query results along with all the child objects if any.&lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;Easy to Learn:&lt;/b&gt;      Hibernate Queries are easy to learn and it can be easily implemented in      the applications.&lt;br /&gt;         &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;Support for Advance      features:&lt;/b&gt; HQL contains many advance features such as pagination, fetch      join with dynamic profiling, Inner/outer/full joins, Cartesian products.      It also supports Projection, Aggregation (max, avg) and grouping,      Ordering, Sub queries and SQL function calls.&lt;br /&gt;        &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;Database independent:&lt;/b&gt;      Queries written in HQL are database independent (If database supports the      underlying feature). &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Understanding HQL Syntax&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;Any Hibernate Query Language may consist of following elements:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Clauses &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Aggregate functions &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;Subqueries &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Clauses in the HQL are:&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/hibernatefromclauseexample.shtml"&gt;from&lt;/a&gt;&lt;/b&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/selectclause.shtml"&gt;select&lt;/a&gt;&lt;/b&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/hqlwhereclauseexample.shtml"&gt;where&lt;/a&gt;&lt;/b&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/hibernateorderbyexample.shtml"&gt;order      by&lt;/a&gt;&lt;/b&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/groupbyclauseexample.shtml"&gt;group      by&lt;/a&gt;&lt;/b&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Aggregate functions are:&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/hibernate-avg.shtml"&gt;avg(...)&lt;/a&gt;&lt;/b&gt;,      &lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/groupbyclauseexample.shtml"&gt;sum(...)&lt;/a&gt;&lt;/b&gt;,      &lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/hibernate-min.shtml"&gt;min(...)&lt;/a&gt;&lt;/b&gt;,      &lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/hibernate-max.shtml"&gt;max(...)&lt;/a&gt;&lt;/b&gt;       &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;&lt;b&gt;&lt;a href="http://www.roseindia.net/hibernate/hibernate-count.shtml"&gt;count(*)&lt;/a&gt;&lt;/b&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: navy;"&gt;count(...),      count(distinct ...), count(all...) &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;Subqueries&lt;/span&gt;&lt;/b&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;Subqueries are nothing but its a query within another query. Hibernate supports Subqueries if the underlying database supports it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;In this lesson we will create insurance table and populate it with the data. We will use insurance table for rest of the HQL tutorial.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: navy;"&gt;To create the insurance table and insert the sample data, run the following sql query:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="color: navy;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 156) none repeat scroll 0% 50%; width: 74%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0" width="74%"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 100%;" width="100%"&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;/*Table structure for table `insurance` */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;drop table if exists `insurance`;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;CREATE TABLE `insurance` (&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;span style=""&gt;  &lt;/span&gt;`ID` int(11) NOT NULL default '0',&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;span style=""&gt;  &lt;/span&gt;`insurance_name` varchar(50) default NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;span style=""&gt;  &lt;/span&gt;`invested_amount` int(11) default NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;span style=""&gt;  &lt;/span&gt;`investement_date` datetime default NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;span style=""&gt;  &lt;/span&gt;PRIMARY KEY&lt;span style=""&gt;  &lt;/span&gt;(`ID`)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;) TYPE=MyISAM;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;/*Data for the table `insurance` */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (1,'Car Insurance',1000,'2005-01-05 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (2,'Life Insurance',100,'2005-10-01 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (3,'Life Insurance',500,'2005-10-15 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (4,'Car Insurance',2500,'2005-01-01 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (5,'Dental Insurance',500,'2004-01-01 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (6,'Life Insurance',900,'2003-01-01 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (7,'Travel Insurance',2000,'2005-02-02 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (8,'Travel Insurance',600,'2005-03-03 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (9,'Medical Insurance',700,'2005-04-04 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (10,'Medical Insurance',900,'2005-03-03 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (11,'Home Insurance',800,'2005-02-02 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (12,'Home Insurance',750,'2004-09-09 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (13,'Motorcycle Insurance',900,'2004-06-06 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: navy;"&gt;insert into `insurance` values (14,'Motorcycle Insurance',780,'2005-03-03 &lt;/span&gt;&lt;st1:time minute="0" hour="0"&gt;&lt;span style="color: navy;"&gt;00:00:00&lt;/span&gt;&lt;/st1:time&gt;&lt;span style="color: navy;"&gt;');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;In this lesson we will write example code to select the data from Insurance table using Hibernate Select Clause. The select clause picks up objects and properties to return in the query result set. Here is the query:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: blue;"&gt;Select insurance.lngInsuranceId, insurance.insuranceName, insurance.investementAmount, insurance.investementDate from Insurance insurance&lt;/span&gt;&lt;span style="color: navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;which selects all the rows (&lt;b&gt;insurance.lngInsuranceId, insurance.insuranceName, insurance.investementAmount, insurance.investementDate&lt;/b&gt;) from Insurance table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="color: navy;"&gt;Hibernate generates the necessary sql query and selects all the records from Insurance table. Here is the code of our java file which shows how select HQL can be used:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="background: rgb(255, 255, 153) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" border="1" cellpadding="0" cellspacing="0"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 2.25pt;" nowrap="nowrap" valign="top"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;package &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;roseindia.tutorial.hibernate;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.Session;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.*;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;org.hibernate.cfg.*;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;import &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;java.util.*;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;/**&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 159, 191);"&gt;@author &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;Deepak Kumar&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* http://www.roseindia.net&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;* HQL Select Clause Example&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 95, 191);"&gt;*/&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public class &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;SelectClauseExample {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public static void &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;main(String[] args) {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Session session = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;null&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;try&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;{&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;// This step will read hibernate.cfg.xml and prepare hibernate for use&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;SessionFactory sessionFactory = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Configuration().configure()&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.buildSessionFactory();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;session =sessionFactory.openSession();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//Create Select Clause HQL&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;String SQL_QUERY =&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Select insurance.lngInsuranceId,insurance.insuranceName," &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;+ &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"insurance.investementAmount,insurance.investementDate from Insurance insurance"&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Query query = session.createQuery(SQL_QUERY);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;     &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;for&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;(Iterator it=query.iterate();it.hasNext();){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;       &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;Object[] row = (Object[]) it.next();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;       &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"ID: " &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;+ row[&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(153, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;]);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;       &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Name: " &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;+ row[&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(153, 0, 0);"&gt;1&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;]);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;       &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Amount: " &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;+ row[&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(153, 0, 0);"&gt;2&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;]);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;        &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;session.close();&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;(Exception e){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.out.println(e.getMessage());&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;finally&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;{&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;    &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: white;"&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: navy;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="color: navy;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;b&gt;&lt;span style="color: navy;"&gt;http://www.roseindia.net/hibernate/index.shtml&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-3486995591671158973?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/3486995591671158973/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=3486995591671158973' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/3486995591671158973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/3486995591671158973'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/09/hibernate.html' title='Hibernate'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-4955681665840128360</id><published>2007-08-20T00:54:00.000-07:00</published><updated>2007-08-20T00:58:39.622-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SCJP 1.5 Mocks'/><title type='text'>SCJP 1.5 Mocks</title><content type='html'>&lt;p&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a target="_blank" href="http://enigma.vm.bytemark.co.uk/webstart.html"&gt;John Meyer's SCJP  1.5 exam&lt;/a&gt; with GUI support for drag and drops.  &lt;/li&gt;&lt;li&gt;&lt;a target="_blank" href="http://www.whizlabs.com/scjp/scjp-5.0-details.html"&gt;WhizLabs SCJP  Preparation Kit&lt;/a&gt; with free sample exam  &lt;/li&gt;&lt;li&gt;EPractize Labs free demo: &lt;a target="_blank" href="http://www.epractizelabs.com/scjp-exam-5-prepkit.html"&gt;25 questions&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;ENTHUWARE's JQPlus V5 - 11 Tests - Most Advanced Java Based Simulator - &lt;a target="_blank" href="http://www.enthuware.com/jqplus/index.html"&gt;Free Sample Exam&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;eXamulator: &lt;a target="_blank" href="http://www.examulator.com/phezam/login.php"&gt;62  questions in total&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;eJavaGuru.com's &lt;a target="_blank" href="http://www.ejavaguru.com/scjp5freemockexam.php"&gt;quiz on Enums&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a target="_blank" href="http://www.javablackbelt.com/QuestDefListing.wwa"&gt;JavaBlackBelt.com&lt;/a&gt;   &lt;/li&gt;&lt;li&gt;&lt;a target="_blank" href="http://www.examulator.com/phezam/login.php"&gt;Marcus Green's 1.5  exam&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a target="_blank" href="http://www.ucertify.com/vendors/Sun.html"&gt;uCertify Java Preparation  Kits&lt;/a&gt; with free Practice Test and Study Notes, Article and How Tos.  &lt;/li&gt;&lt;li&gt;&lt;a target="_blank" href="http://www.blogger.com/java/Cafe4Java"&gt;Cafe4Java&lt;/a&gt;'s Collection of &lt;a target="_blank" href="http://cafe4java.com/mockexams/mockexamlist.php"&gt;free SCJP 5.0 exam  questions&lt;/a&gt;, arranged by (sub)objectives like collections, file I/O etc&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-4955681665840128360?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/4955681665840128360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=4955681665840128360' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4955681665840128360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4955681665840128360'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/08/scjp-15-mocks.html' title='SCJP 1.5 Mocks'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-6341733492840507140</id><published>2007-08-07T22:09:00.000-07:00</published><updated>2007-08-07T22:23:44.640-07:00</updated><title type='text'>SCJP Mock Exams</title><content type='html'>&lt;div&gt;&lt;br /&gt;&lt;a href="http://www.akgupta.com/Java/mock_exam.htm" target="_blank"&gt;http://www.akgupta.com/Java/mock_exam.htm&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java.about.com/gi/dynamic/offsite.htm?zi=1/XJ&amp;sdn=java&amp;amp;amp;amp;amp;amp;amp;cdn=compute&amp;tm=15&amp;amp;gps=142_240_1020_521&amp;f=00&amp;amp;su=p284.8.150.ip_&amp;tt=3&amp;amp;bt=0&amp;bts=0&amp;amp;zu=http%3A//www.jdiscuss.com/index.html"&gt;http://java.about.com/gi/dynamic/offsite.htm&lt;/a&gt;  &lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java.about.com/gi/dynamic/offsite.htm?zi=1/XJ&amp;sdn=java&amp;amp;amp;amp;amp;amp;amp;cdn=compute&amp;tm=30&amp;amp;gps=148_408_1020_521&amp;f=00&amp;amp;su=p284.8.150.ip_&amp;tt=3&amp;amp;bt=0&amp;bts=0&amp;amp;zu=http%3A//www.javaprepare.com/quests/test.html"&gt;http://java.about.com/gi/dynamic/offsite.htm &lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;a target="_blank" href="http://www.javacertificate.net/scjp_1.htm"&gt;http://www.javacertificate.net/scjp_1.htm&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;   &lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;a target="_blank" href="http://www.javaprepare.com/quests/test.html"&gt;http://www.javaprepare.com/quests/test.html&lt;/a&gt;&lt;br /&gt;&lt;/div&gt; &lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;a target="_blank" href="http://www.javaranch.com/maha/_Mock_Exams/_mock_exams.html"&gt;http://www.javaranch.com/maha/_Mock_Exams/_mock_exams.html&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://www.javacertificationexams.com/scjp-mock-exams.php"&gt;http://www.javacertificationexams.com/scjp-mock-exams.php&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-6341733492840507140?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/6341733492840507140/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=6341733492840507140' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/6341733492840507140'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/6341733492840507140'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/08/scjp-mock-exams.html' title='SCJP Mock Exams'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-1777633269895989453</id><published>2007-08-01T23:59:00.000-07:00</published><updated>2007-08-02T00:02:16.210-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rm'/><category scheme='http://www.blogger.com/atom/ns#' term='pwd'/><category scheme='http://www.blogger.com/atom/ns#' term='cat'/><category scheme='http://www.blogger.com/atom/ns#' term='wc'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='rmdir'/><category scheme='http://www.blogger.com/atom/ns#' term='cd'/><category scheme='http://www.blogger.com/atom/ns#' term='mkdir'/><category scheme='http://www.blogger.com/atom/ns#' term='cp'/><category scheme='http://www.blogger.com/atom/ns#' term='commands'/><category scheme='http://www.blogger.com/atom/ns#' term='ls'/><category scheme='http://www.blogger.com/atom/ns#' term='la'/><title type='text'>Linux Files and Directories</title><content type='html'>&lt;h3&gt;&lt;a name="Display_name_of_current_directory"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=""&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;pwd - Display name of current directory&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;span style="font-family: Arial;"&gt; &lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;The command &lt;b&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;pwd&lt;/span&gt;&lt;/b&gt; is used to display the full path name of the current directory.&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="width: 100%;" border="0" cellpadding="0" cellspacing="0" width="100%"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0in; width: 100%;" valign="top" width="100%"&gt;   &lt;h3&gt;&lt;a name="Switch_to_another_directory"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;cd - Switch to another directory&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;   &lt;p class="style4"&gt;&lt;span style="font-family: Arial;"&gt;To switch to another   directory, the command &lt;b&gt;cd&lt;/b&gt; is used.&lt;/span&gt;&lt;/p&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 55%;" border="1" cellpadding="0" cellspacing="0" width="55%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 20%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Examples&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="80%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" width="20%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;cd&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Will     place you in your &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;home directory&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" width="20%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;cd /&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Will     move you to the &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;root directory&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" width="20%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;cd /etc&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Will     move you to the&lt;strong&gt;&lt;span style="font-family: Arial;"&gt; /etc directory&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" width="20%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;cd ../&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Will     move you &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;back one directory&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;   &lt;hr align="center" size="2" width="100%"&gt;   &lt;/div&gt;   &lt;h3&gt;&lt;a name="Create/Delete_directories"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;mkdir and rmdir - Create/Delete directories&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;   &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;The command &lt;b&gt;mkdir&lt;/b&gt;   is used to create a new directory.&lt;/span&gt;&lt;/p&gt;   &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;The command &lt;b&gt;rmdir&lt;/b&gt;   or &lt;b&gt;rm -r&lt;/b&gt; is used to delete a directory or directories. &lt;span style="color: red;"&gt;Be careful in testing the following delete commands. You   will probably want to create sample directories first.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 75%;" border="1" cellpadding="0" cellspacing="0" width="75%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 34%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="34%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Examples&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 66%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="66%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 34%;" valign="top" width="34%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;mkdir mydirectory&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 66%;" valign="top" width="66%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Will &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;create a new directory&lt;/span&gt;&lt;/strong&gt; named     'mydirectory'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 34%;" valign="top" width="34%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;rmdir existingdirectory&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 66%;" valign="top" width="66%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Will &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;delete&lt;/span&gt;&lt;/strong&gt; the existing directory     named 'existingdirectory'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 34%;" valign="top" width="34%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;rm -r existingdirectories&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 66%;" valign="top" width="66%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Will &lt;b&gt;delete&lt;/b&gt;     the existing directory named 'existingdirectories' and all directories and     files below it.&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;   &lt;hr align="center" size="2" width="100%"&gt;   &lt;/div&gt;   &lt;h3&gt;&lt;a name="List_the_Contents_of_a_directory"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;ls - List the Contents of a directory&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;   &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;The command &lt;b&gt;ls&lt;/b&gt; is   used to the contents of a directory.&lt;/span&gt;&lt;/p&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 75%;" border="1" cellpadding="0" cellspacing="0" width="75%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 20%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Options&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="80%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-l&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;long     listing&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-R&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list     current directory and all other directories within current directory&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style="height: 12.75pt;"&gt;     &lt;td style="padding: 0in; width: 20%; height: 12.75pt;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-a&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%; height: 12.75pt;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list     hidden files&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style="height: 12.75pt;"&gt;     &lt;td style="padding: 0in; width: 20%; height: 12.75pt;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-CF&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%; height: 12.75pt;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list in     column format and append '*' to executable files, '@' to symbolic linked     files, '/' to directories&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style="height: 12.75pt;"&gt;     &lt;td style="padding: 0in; width: 20%; height: 12.75pt;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-r&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%; height: 12.75pt;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list in     reverse alphabetically order&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style="height: 12.75pt;"&gt;     &lt;td style="padding: 0in; width: 20%; height: 12.75pt;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-t&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%; height: 12.75pt;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list     more recent accessed files first&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style="height: 12.75pt;"&gt;     &lt;td style="padding: 0in; width: 20%; height: 12.75pt;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;filename(s)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%; height: 12.75pt;" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Values     to match&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="display: none;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 75%;" border="1" cellpadding="0" cellspacing="0" width="75%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;     &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Examples&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;     &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;ls&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;only     list file/directory names in current directory&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;ls -l&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list     all file/directory information in current directory(long version)&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;ls -R&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list     all files in current directories and below&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;ls -lt&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list     all files, sorted by most recent accessed first&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;ls -lt /etc/rc*&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in;"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;list     files in the '/etc/ directory, only starting with 'rc' and sort results by     most recent&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;   &lt;hr align="center" size="2" width="100%"&gt;   &lt;/div&gt;   &lt;h3&gt;&lt;a name="Wildcards"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;Wildcards&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;   &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Wildcard characters are   used to help find file or directory names&lt;/span&gt;&lt;/p&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 75%;" border="1" cellpadding="0" cellspacing="0" width="75%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 20%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Options&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="80%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" valign="top" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;*&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" valign="top" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;asterisk     symbol is used to represent &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;any&lt;/span&gt;&lt;/strong&gt;     character(s)&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" valign="top" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;?&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" valign="top" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;question     mark is used to represent any &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;single&lt;/span&gt;&lt;/strong&gt;     character&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" valign="top" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;[from-to ]&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" valign="top" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Values     entered within square brackets represent a &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;range&lt;/span&gt;&lt;/strong&gt; (from-to) for a single character&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 20%;" valign="top" width="20%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;[!from-to ]&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 80%;" valign="top" width="80%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Values     entered within square brackets represent a &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;range&lt;/span&gt;&lt;/strong&gt; (from-to) to &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;exclude&lt;/span&gt;&lt;/strong&gt; for a single character&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="display: none;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 89%;" border="1" cellpadding="0" cellspacing="0" width="89%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 15%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="15%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Examples&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 85%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="85%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 15%;" width="15%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;a*&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 85%;" width="85%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;all     files starting with the letter 'a'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 15%;" width="15%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;*z&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 85%;" width="85%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;all     files where the last character is a 'z'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 15%;" width="15%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;a*m&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 85%;" width="85%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;all     files that start with the letter 'a' and end with 'm'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 15%;" width="15%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;th??&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 85%;" width="85%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;all     files that start with 'th' and are only four characters long&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 15%;" width="15%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;[a-c]*&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 85%;" width="85%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;all     files that start with 'a, b or c'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 15%;" width="15%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;x[A-C]*&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 85%;" width="85%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;all     files that start with the letter 'x' and the second character contains 'A,     B or C'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 15%;" width="15%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;[!M-O]*&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 85%;" width="85%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;all     files except those that start with 'M, N or O'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;   &lt;hr align="center" size="2" width="100%"&gt;   &lt;/div&gt;   &lt;h3&gt;&lt;a name="Copy_files"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;cp -   Copy files&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;   &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;To copy a file, the   command &lt;b&gt;cp&lt;/b&gt; is used&lt;/span&gt;&lt;/p&gt;   &lt;p&gt;&lt;em&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Example:&lt;/span&gt;&lt;/em&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;cp   oldfile myfile&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt; - Will copy the existing file 'oldfile' to a new file   'myfile'&lt;/span&gt;&lt;/p&gt;   &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;   &lt;hr align="center" size="2" width="100%"&gt;   &lt;/div&gt;   &lt;h3&gt;&lt;a name="Rename_files"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;mv -   Rename files&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;   &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;The command &lt;b&gt;mv&lt;/b&gt; is   used to rename a file&lt;/span&gt;&lt;/p&gt;   &lt;p&gt;&lt;em&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Example:&lt;/span&gt;&lt;/em&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;mv   myfile yourfile&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;- Will rename the file 'myfile' to 'yourfile'&lt;/span&gt;&lt;/p&gt;   &lt;p&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;   &lt;hr align="center" size="2" width="100%"&gt;   &lt;/div&gt;   &lt;h3&gt;&lt;a name="Delete_files"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;rm -   Delete files&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 75%;" border="1" cellpadding="0" cellspacing="0" width="75%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 18%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="18%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Examples&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 82%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="82%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 18%;" valign="top" width="18%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;rm myfile&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 82%;" valign="top" width="82%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;remove     the file 'myfile'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 18%;" valign="top" width="18%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;rm -i abc*&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 82%;" valign="top" width="82%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;prompt     to remove each file in current directory starting with 'abc'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 18%;" valign="top" width="18%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;rm abc*&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 82%;" valign="top" width="82%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;remove     all files in current directory starting with 'abc' automatically&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;   &lt;hr align="center" size="2" width="100%"&gt;   &lt;/div&gt;   &lt;h3&gt;&lt;a name="Count_the_number_of_lines_or_characters"&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;wc - Count the number of lines or characters&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;   &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;The command &lt;b&gt;wc&lt;/b&gt; is   used to count lines, words or characters in a file or piped results from   another command. &lt;/span&gt;&lt;/p&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 38%;" border="1" cellpadding="0" cellspacing="0" width="38%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 28%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="28%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Options&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 72%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="72%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 28%;" width="28%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-c&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 72%;" width="72%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Number     of characters&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 28%;" width="28%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-w&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 72%;" width="72%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Number     of words&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style="height: 12.75pt;"&gt;     &lt;td style="padding: 0in; width: 28%; height: 12.75pt;" width="28%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;-l&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 72%; height: 12.75pt;" width="72%"&gt;     &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 28%;" width="28%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;filename&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 72%;" width="72%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;file     name(s) to use&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="display: none;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;div align="center"&gt;   &lt;table class="MsoNormalTable" style="width: 88%;" border="1" cellpadding="0" cellspacing="0" width="88%"&gt;    &lt;tbody&gt;&lt;tr style=""&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 24%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="24%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;Examples&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; background: rgb(0, 51, 153) none repeat scroll 0% 50%; width: 76%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="76%"&gt;     &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: white;"&gt;What it does&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 24%;" valign="top" width="24%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;wc /etc/sendmail.cf&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 76%;" valign="top" width="76%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Lists     the number of lines, words and characters in the file 'sendmail.cf'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;    &lt;tr style=""&gt;     &lt;td style="padding: 0in; width: 24%;" valign="top" width="24%"&gt;     &lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;ls /etc | wc -l&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;     &lt;/td&gt;     &lt;td style="padding: 0in; width: 76%;" valign="top" width="76%"&gt;     &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Lists     the number of files and directories in the directory 'etc'&lt;/span&gt;&lt;/p&gt;     &lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;   &lt;/div&gt;   &lt;p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;  &lt;hr align="center" size="2" width="100%"&gt;  &lt;/div&gt;  &lt;h3&gt;&lt;a name="file"&gt;&lt;/a&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;file - Display Type-of-File Description&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Files can consist of several types. The command file is used to display a description for the type.&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Example:&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt; &lt;strong&gt;&lt;span style="font-family: Arial; color: rgb(0, 102, 0);"&gt;file a*&lt;/span&gt;&lt;/strong&gt; will list all files in the current directory that start with the letter "a" and provide a description for the file type.&lt;/span&gt;&lt;/p&gt;  &lt;div class="MsoNormal" style="text-align: center;" align="center"&gt;  &lt;hr align="center" size="2" width="100%"&gt;  &lt;/div&gt;  &lt;h3&gt;&lt;a name="cat"&gt;&lt;/a&gt;&lt;span style="font-family: Arial; color: rgb(0, 51, 153);"&gt;cat - concatenate files&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;The command &lt;strong&gt;&lt;span style="font-family: Arial;"&gt;cat&lt;/span&gt;&lt;/strong&gt; is a multi-purpose utility and is mostly used with TEXT files.&lt;/span&gt;&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Create a &lt;b&gt;new file&lt;/b&gt; and optionally allow the &lt;b&gt;manual      entry of contents&lt;/b&gt;&lt;/span&gt; &lt;/li&gt;&lt;ul type="circle"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;cat       &gt;[filename]&lt;/span&gt;&lt;/b&gt; &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Example: &lt;strong&gt;&lt;span style="font-family: Arial; color: rgb(0, 102, 0);"&gt;cat &gt;myfile&lt;/span&gt;&lt;/strong&gt;       will create a file named myfile and allow you to enter contents. &lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Press &lt;b&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;Control-D&lt;/span&gt; to exit&lt;/b&gt; entry mode. &lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: red;"&gt;WARNING: If       "myfile" already existed, this command would replace the old       file with the contents of the new file. &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Combine text files&lt;/span&gt;&lt;/b&gt; &lt;/li&gt;&lt;ul type="circle"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;cat file1 file2       &gt;newfile - &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;This       will combine &lt;span style="color: rgb(0, 51, 153);"&gt;file1&lt;/span&gt; and &lt;span style="color: rgb(0, 51, 153);"&gt;file2&lt;/span&gt; into &lt;span style="color: rgb(0, 51, 153);"&gt;newfile&lt;/span&gt;.&lt;/span&gt;       &lt;/li&gt;&lt;/ul&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Dissplay the contents&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt; of a file&lt;/span&gt; &lt;/li&gt;&lt;ul type="circle"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;cat myfile&lt;/span&gt;&lt;/b&gt;       &lt;/li&gt;&lt;/ul&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Delete the contents&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt; of a file&lt;/span&gt; &lt;/li&gt;&lt;ul type="circle"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: rgb(0, 102, 0);"&gt;cat /dev/null       &gt;myfile&lt;/span&gt;&lt;/b&gt; &lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-1777633269895989453?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/1777633269895989453/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=1777633269895989453' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1777633269895989453'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/1777633269895989453'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/08/linux-files-and-directories.html' title='Linux Files and Directories'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-2997186271524873910</id><published>2007-07-27T07:43:00.000-07:00</published><updated>2007-07-27T07:53:22.562-07:00</updated><title type='text'>HIBERNATE - Relational Persistence for Idiomatic Java</title><content type='html'>&lt;div class="chapter" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title"&gt;&lt;a name="tutorial"&gt;&lt;/a&gt;Introduction to Hibernate&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="sect1" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both"&gt;&lt;a name="tutorial-intro"&gt;&lt;/a&gt;1.1.&amp;nbsp;Preface&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;            This chapter is an introductory tutorial for new users of Hibernate. We start&lt;br /&gt;            with a simple command line application using an in-memory database and develop&lt;br /&gt;            it in easy to understand steps.&lt;br /&gt;        &lt;/p&gt;&lt;p&gt;&lt;br /&gt;            This tutorial is intended for new users of Hibernate but requires Java and&lt;br /&gt;            SQL knowledge. It is based on a tutorial by Michael Gloegl, the third-party&lt;br /&gt;            libraries we name are for JDK 1.4 and 5.0. You might need others for JDK 1.3.&lt;br /&gt;        &lt;/p&gt;&lt;p&gt;&lt;br /&gt;            The source code for the tutorial is included in the distribution in the&lt;br /&gt;            &lt;tt class="literal"&gt;doc/reference/tutorial/&lt;/tt&gt; directory.&lt;br /&gt;        &lt;/p&gt;&lt;/div&gt;&lt;div class="sect1" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both"&gt;&lt;a name="tutorial-firstapp"&gt;&lt;/a&gt;1.2.&amp;nbsp;Part 1 - The first Hibernate Application&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;            First, we'll create a simple console-based Hibernate application. We use an&lt;br /&gt;            Java database (HSQL DB), so we do not have to install any database server.&lt;br /&gt;        &lt;/p&gt;&lt;p&gt;&lt;br /&gt;            Let's assume we need a small database application that can store events we want to&lt;br /&gt;            attend, and information about the hosts of these events.&lt;br /&gt;        &lt;/p&gt;&lt;p&gt;&lt;br /&gt;            The first thing we do, is set up our development directory and put all the&lt;br /&gt;            Java libraries we need into it. Download the Hibernate distribution from the&lt;br /&gt;            Hibernate website. Extract the package and place all required libraries&lt;br /&gt;            found in &lt;tt class="literal"&gt;/lib&lt;/tt&gt; into into the &lt;tt class="literal"&gt;/lib&lt;/tt&gt; directory&lt;br /&gt;            of your new development working directory. It should look like this:&lt;br /&gt;        &lt;/p&gt;&lt;pre class="programlisting"&gt;.&lt;br /&gt;+lib&lt;br /&gt;  antlr.jar&lt;br /&gt;  cglib.jar&lt;br /&gt;  asm.jar&lt;br /&gt;  asm-attrs.jars&lt;br /&gt;  commons-collections.jar&lt;br /&gt;  commons-logging.jar&lt;br /&gt;  hibernate3.jar&lt;br /&gt;  jta.jar&lt;br /&gt;  dom4j.jar&lt;br /&gt;  log4j.jar &lt;/pre&gt;&lt;p&gt;&lt;br /&gt;            This is the minimum set of required libraries (note that we also copied&lt;br /&gt;            hibernate3.jar, the main archive) for Hibernate &lt;span class="emphasis"&gt;&lt;em&gt;at the time of writing&lt;/em&gt;&lt;/span&gt;.&lt;br /&gt;            The Hibernate release you are using might require more or less libraries. See the&lt;br /&gt;            &lt;tt class="literal"&gt;README.txt&lt;/tt&gt; file in the &lt;tt class="literal"&gt;lib/&lt;/tt&gt; directory of the&lt;br /&gt;            Hibernate distribution for more information about required and optional third-party&lt;br /&gt;            libraries. (Actually, Log4j is not required but preferred by many developers.)&lt;br /&gt;        &lt;/p&gt;&lt;p&gt;&lt;br /&gt;            Next we create a class that represents the event we want to store in database.&lt;br /&gt;        &lt;/p&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-firstapp-firstclass"&gt;&lt;/a&gt;1.2.1.&amp;nbsp;The first class&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                Our first persistent class is a simple JavaBean class with some properties:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;package events;&lt;br /&gt;&lt;br /&gt;import java.util.Date;&lt;br /&gt;&lt;br /&gt;public class Event {&lt;br /&gt;    private Long id;&lt;br /&gt;&lt;br /&gt;    private String title;&lt;br /&gt;    private Date date;&lt;br /&gt;&lt;br /&gt;    public Event() {}&lt;br /&gt;&lt;br /&gt;    public Long getId() {&lt;br /&gt;        return id;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void setId(Long id) {&lt;br /&gt;        this.id = id;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public Date getDate() {&lt;br /&gt;        return date;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setDate(Date date) {&lt;br /&gt;        this.date = date;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getTitle() {&lt;br /&gt;        return title;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setTitle(String title) {&lt;br /&gt;        this.title = title;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                You can see that this class uses standard JavaBean naming conventions for property&lt;br /&gt;                getter and setter methods, as well as private visibility for the fields. This is&lt;br /&gt;                a recommended design - but not required. Hibernate can also access fields directly,&lt;br /&gt;                the benefit of accessor methods is robustness for refactoring. The no-argument&lt;br /&gt;                constructor is required to instantiate an object of this class through reflection.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                The &lt;tt class="literal"&gt;id&lt;/tt&gt; property holds a unique identifier value for a particular event.&lt;br /&gt;                All persistent entity classes (there are less important dependent classes as well) will need&lt;br /&gt;                such an identifier property if we want to use the full feature set of Hibernate. In fact,&lt;br /&gt;                most applications (esp. web applications) need to distinguish objects by identifier, so you&lt;br /&gt;                should consider this a feature rather than a limitation. However, we usually don't manipulate&lt;br /&gt;                the identity of an object, hence the setter method should be private. Only Hibernate will assign&lt;br /&gt;                identifiers when an object is saved. You can see that Hibernate can access public, private,&lt;br /&gt;                and protected accessor methods, as well as (public, private, protected) fields directly. The&lt;br /&gt;                choice is up to you and you can match it to fit your application design.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                The no-argument constructor is a requirement for all persistent classes; Hibernate&lt;br /&gt;                has to create objects for you, using Java Reflection. The constructor can be&lt;br /&gt;                private, however, package visibility is required for runtime proxy generation and&lt;br /&gt;                efficient data retrieval without bytecode instrumentation.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Place this Java source file in a directory called &lt;tt class="literal"&gt;src&lt;/tt&gt; in the&lt;br /&gt;                development folder, and in its correct package. The directory should now look like this:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;.&lt;br /&gt;+lib&lt;br /&gt;  &amp;lt;Hibernate and third-party libraries&amp;gt;&lt;br /&gt;+src&lt;br /&gt;  +events&lt;br /&gt;    Event.java&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                In the next step, we tell Hibernate about this persistent class.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-firstapp-mapping"&gt;&lt;/a&gt;1.2.2.&amp;nbsp;The mapping file&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                Hibernate needs to know how to load and store objects of the persistent class.&lt;br /&gt;                This is where the Hibernate mapping file comes into play. The mapping file&lt;br /&gt;                tells Hibernate what table in the database it has to access, and what columns&lt;br /&gt;                in that table it should use.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                The basic structure of a mapping file looks like this:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"&lt;br /&gt;        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt;[...]&lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Note that the Hibernate DTD is very sophisticated. You can use it for&lt;br /&gt;                auto-completion of XML mapping elements and attributes in your editor or&lt;br /&gt;                IDE. You also should open up the DTD file in your text editor - it's the&lt;br /&gt;                easiest way to get an overview of all elements and attributes and to see&lt;br /&gt;                the defaults, as well as some comments. Note that Hibernate will not&lt;br /&gt;                load the DTD file from the web, but first look it up from the classpath&lt;br /&gt;                of the application. The DTD file is included in &lt;tt class="literal"&gt;hibernate3.jar&lt;/tt&gt;&lt;br /&gt;                as well as in the &lt;tt class="literal"&gt;src/&lt;/tt&gt; directory of the Hibernate distribution.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                We will omit the DTD declaration in future examples to shorten the code. It is&lt;br /&gt;                of course not optional.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Between the two &lt;tt class="literal"&gt;hibernate-mapping&lt;/tt&gt; tags, include a&lt;br /&gt;                &lt;tt class="literal"&gt;class&lt;/tt&gt; element. All persistent entity classes (again, there&lt;br /&gt;                might be dependent classes later on, which are not first-class entities) need&lt;br /&gt;                such a mapping, to a table in the SQL database:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;class name="events.Event" table="EVENTS"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;/class&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                So far we told Hibernate how to persist and load object of class &lt;tt class="literal"&gt;Event&lt;/tt&gt;&lt;br /&gt;                to the table &lt;tt class="literal"&gt;EVENTS&lt;/tt&gt;, each instance represented by a row in that table.&lt;br /&gt;                Now we continue with a mapping of the unique identifier property to the tables primary key.&lt;br /&gt;                In addition, as we don't want to care about handling this identifier, we configure Hibernate's&lt;br /&gt;                identifier generation strategy for a surrogate primary key column:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;class name="events.Event" table="EVENTS"&amp;gt;&lt;br /&gt;        &amp;lt;id name="id" column="EVENT_ID"&amp;gt;&lt;br /&gt;            &amp;lt;generator class="native"/&amp;gt;&lt;br /&gt;        &amp;lt;/id&amp;gt;&lt;br /&gt;    &amp;lt;/class&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                The &lt;tt class="literal"&gt;id&lt;/tt&gt; element is the declaration of the identifer property,&lt;br /&gt;                &lt;tt class="literal"&gt;name="id"&lt;/tt&gt; declares the name of the Java property -&lt;br /&gt;                Hibernate will use the getter and setter methods to access the property.&lt;br /&gt;                The column attribute tells Hibernate which column of the&lt;br /&gt;                &lt;tt class="literal"&gt;EVENTS&lt;/tt&gt; table we use for this primary key. The nested&lt;br /&gt;                &lt;tt class="literal"&gt;generator&lt;/tt&gt; element specifies the identifier generation strategy,&lt;br /&gt;                in this case we used &lt;tt class="literal"&gt;native&lt;/tt&gt;, which picks the best strategy depending&lt;br /&gt;                on the configured database (dialect). Hibernate supports database generated, globally&lt;br /&gt;                unique, as well as application assigned identifiers (or any strategy you have written&lt;br /&gt;                an extension for).&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Finally we include declarations for the persistent properties of the class in&lt;br /&gt;                the mapping file. By default, no properties of the class are considered&lt;br /&gt;                persistent:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;class name="events.Event" table="EVENTS"&amp;gt;&lt;br /&gt;        &amp;lt;id name="id" column="EVENT_ID"&amp;gt;&lt;br /&gt;            &amp;lt;generator class="native"/&amp;gt;&lt;br /&gt;        &amp;lt;/id&amp;gt;&lt;br /&gt;        &amp;lt;property name="date" type="timestamp" column="EVENT_DATE"/&amp;gt;&lt;br /&gt;        &amp;lt;property name="title"/&amp;gt;&lt;br /&gt;    &amp;lt;/class&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Just as with the &lt;tt class="literal"&gt;id&lt;/tt&gt; element, the &lt;tt class="literal"&gt;name&lt;/tt&gt;&lt;br /&gt;                attribute of the &lt;tt class="literal"&gt;property&lt;/tt&gt; element tells Hibernate which getter&lt;br /&gt;                and setter methods to use. So, in this case, Hibernate will look for&lt;br /&gt;                &lt;tt class="literal"&gt;getDate()/setDate()&lt;/tt&gt;, as well as &lt;tt class="literal"&gt;getTitle()/setTitle()&lt;/tt&gt;.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Why does the &lt;tt class="literal"&gt;date&lt;/tt&gt; property mapping include the&lt;br /&gt;                &lt;tt class="literal"&gt;column&lt;/tt&gt; attribute, but the &lt;tt class="literal"&gt;title&lt;/tt&gt;&lt;br /&gt;                doesn't? Without the &lt;tt class="literal"&gt;column&lt;/tt&gt; attribute Hibernate&lt;br /&gt;                by default uses the property name as the column name. This works fine for&lt;br /&gt;                &lt;tt class="literal"&gt;title&lt;/tt&gt;. However, &lt;tt class="literal"&gt;date&lt;/tt&gt; is a reserved&lt;br /&gt;                keyword in most database, so we better map it to a different name.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                The next interesting thing is that the &lt;tt class="literal"&gt;title&lt;/tt&gt; mapping also lacks&lt;br /&gt;                a &lt;tt class="literal"&gt;type&lt;/tt&gt; attribute. The types we declare and use in the mapping&lt;br /&gt;                files are not, as you might expect, Java data types. They are also not SQL&lt;br /&gt;                database types. These types are so called &lt;span class="emphasis"&gt;&lt;em&gt;Hibernate mapping types&lt;/em&gt;&lt;/span&gt;,&lt;br /&gt;                converters which can translate from Java to SQL data types and vice versa. Again,&lt;br /&gt;                Hibernate will try to determine the correct conversion and mapping type itself if&lt;br /&gt;                the &lt;tt class="literal"&gt;type&lt;/tt&gt; attribute is not present in the mapping. In some cases this&lt;br /&gt;                automatic detection (using Reflection on the Java class) might not have the default you&lt;br /&gt;                expect or need. This is the case with the &lt;tt class="literal"&gt;date&lt;/tt&gt; property. Hibernate can't&lt;br /&gt;                know if the property (which is of &lt;tt class="literal"&gt;java.util.Date&lt;/tt&gt;) should map to a&lt;br /&gt;                SQL &lt;tt class="literal"&gt;date&lt;/tt&gt;, &lt;tt class="literal"&gt;timestamp&lt;/tt&gt;, or &lt;tt class="literal"&gt;time&lt;/tt&gt; column.&lt;br /&gt;                We preserve full date and time information by mapping the property with a&lt;br /&gt;                &lt;tt class="literal"&gt;timestamp&lt;/tt&gt; converter.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                This mapping file should be saved as &lt;tt class="literal"&gt;Event.hbm.xml&lt;/tt&gt;, right in&lt;br /&gt;                the directory next to the &lt;tt class="literal"&gt;Event&lt;/tt&gt; Java class source file.&lt;br /&gt;                The naming of mapping files can be arbitrary, however the &lt;tt class="literal"&gt;hbm.xml&lt;/tt&gt;&lt;br /&gt;                suffix  is a convention in the Hibernate developer community. The directory structure&lt;br /&gt;                should now look like this:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;.&lt;br /&gt;+lib&lt;br /&gt;  &amp;lt;Hibernate and third-party libraries&amp;gt;&lt;br /&gt;+src&lt;br /&gt;  +events&lt;br /&gt;    Event.java&lt;br /&gt;    Event.hbm.xml&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                 We continue with the main configuration of Hibernate.&lt;br /&gt;             &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-firstapp-configuration"&gt;&lt;/a&gt;1.2.3.&amp;nbsp;Hibernate configuration&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                We now have a persistent class and its mapping file in place. It is time to configure&lt;br /&gt;                Hibernate. Before we do this, we will need a database. HSQL DB, a java-based SQL DBMS,&lt;br /&gt;                can be downloaded from the HSQL DB website. Actually, you only need the &lt;tt class="literal"&gt;hsqldb.jar&lt;/tt&gt;&lt;br /&gt;                from this download. Place this file in the &lt;tt class="literal"&gt;lib/&lt;/tt&gt; directory of the&lt;br /&gt;                development folder.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Create a directory called &lt;tt class="literal"&gt;data&lt;/tt&gt; in the root of the development directory -&lt;br /&gt;                this is where HSQL DB will store its data files. Now start the database by running&lt;br /&gt;                &lt;tt class="literal"&gt;java -classpath ../lib/hsqldb.jar org.hsqldb.Server&lt;/tt&gt; in this data directory.&lt;br /&gt;                You can see it start up and bind to a TCP/IP socket, this is where our application&lt;br /&gt;                will connect later. If you want to start with a fresh database during this tutorial,&lt;br /&gt;                shutdown HSQL DB (press &lt;tt class="literal"&gt;CTRL + C&lt;/tt&gt; in the window), delete all files in the&lt;br /&gt;                &lt;tt class="literal"&gt;data/&lt;/tt&gt; directory, and start HSQL DB again.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Hibernate is the layer in your application which connects to this database, so it needs&lt;br /&gt;                connection information. The connections are made through a JDBC connection pool, which we&lt;br /&gt;                also have to configure. The Hibernate distribution contains several open source JDBC connection&lt;br /&gt;                pooling tools, but will use the Hibernate built-in connection pool for this tutorial. Note that&lt;br /&gt;                you have to copy the required library into your classpath and use different&lt;br /&gt;                connection pooling settings if you want to use a production-quality third party&lt;br /&gt;                JDBC pooling software.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                For Hibernate's configuration, we can use a simple &lt;tt class="literal"&gt;hibernate.properties&lt;/tt&gt; file, a&lt;br /&gt;                slightly more sophisticated &lt;tt class="literal"&gt;hibernate.cfg.xml&lt;/tt&gt; file, or even complete&lt;br /&gt;                programmatic setup. Most users prefer the XML configuration file:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;?xml version='1.0' encoding='utf-8'?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE hibernate-configuration PUBLIC&lt;br /&gt;        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"&lt;br /&gt;        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;hibernate-configuration&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;session-factory&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;!-- Database connection settings --&amp;gt;&lt;br /&gt;        &amp;lt;property name="connection.driver_class"&amp;gt;org.hsqldb.jdbcDriver&amp;lt;/property&amp;gt;&lt;br /&gt;        &amp;lt;property name="connection.url"&amp;gt;jdbc:hsqldb:hsql://localhost&amp;lt;/property&amp;gt;&lt;br /&gt;        &amp;lt;property name="connection.username"&amp;gt;sa&amp;lt;/property&amp;gt;&lt;br /&gt;        &amp;lt;property name="connection.password"&amp;gt;&amp;lt;/property&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;!-- JDBC connection pool (use the built-in) --&amp;gt;&lt;br /&gt;        &amp;lt;property name="connection.pool_size"&amp;gt;1&amp;lt;/property&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;!-- SQL dialect --&amp;gt;&lt;br /&gt;        &amp;lt;property name="dialect"&amp;gt;org.hibernate.dialect.HSQLDialect&amp;lt;/property&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;!-- Enable Hibernate's automatic session context management --&amp;gt;&lt;br /&gt;        &amp;lt;property name="current_session_context_class"&amp;gt;thread&amp;lt;/property&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;!-- Disable the second-level cache  --&amp;gt;&lt;br /&gt;        &amp;lt;property name="cache.provider_class"&amp;gt;org.hibernate.cache.NoCacheProvider&amp;lt;/property&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;!-- Echo all executed SQL to stdout --&amp;gt;&lt;br /&gt;        &amp;lt;property name="show_sql"&amp;gt;true&amp;lt;/property&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;!-- Drop and re-create the database schema on startup --&amp;gt;&lt;br /&gt;        &amp;lt;property name="hbm2ddl.auto"&amp;gt;create&amp;lt;/property&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;mapping resource="events/Event.hbm.xml"/&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;/session-factory&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/hibernate-configuration&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Note that this XML configuration uses a different DTD. We configure&lt;br /&gt;                Hibernate's &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt; - a global factory responsible&lt;br /&gt;                for a particular database. If you have several databases, use several&lt;br /&gt;                &lt;tt class="literal"&gt;&amp;lt;session-factory&amp;gt;&lt;/tt&gt; configurations, usually in&lt;br /&gt;                several configuration files (for easier startup).&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                The first four &lt;tt class="literal"&gt;property&lt;/tt&gt; elements contain the necessary&lt;br /&gt;                configuration for the JDBC connection. The dialect &lt;tt class="literal"&gt;property&lt;/tt&gt;&lt;br /&gt;                element specifies the particular SQL variant Hibernate generates.&lt;br /&gt;                Hibernate's automatic session management for persistence contexts will&lt;br /&gt;                come in handy as you will soon see.&lt;br /&gt;                The &lt;tt class="literal"&gt;hbm2ddl.auto&lt;/tt&gt; option turns on automatic generation of&lt;br /&gt;                database schemas - directly into the database. This can of course also be turned&lt;br /&gt;                off (by removing the config option) or redirected to a file with the help of&lt;br /&gt;                the &lt;tt class="literal"&gt;SchemaExport&lt;/tt&gt; Ant task. Finally, we add the mapping file(s)&lt;br /&gt;                for persistent classes to the configuration.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Copy this file into the source directory, so it will end up in the&lt;br /&gt;                root of the classpath. Hibernate automatically looks for a file called&lt;br /&gt;                &lt;tt class="literal"&gt;hibernate.cfg.xml&lt;/tt&gt; in the root of the classpath, on startup.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-firstapp-ant"&gt;&lt;/a&gt;1.2.4.&amp;nbsp;Building with Ant&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                We'll now build the tutorial with Ant. You will need to have Ant installed - get&lt;br /&gt;                it from the &lt;a href="http://ant.apache.org/bindownload.cgi" target="_top"&gt;Ant download page&lt;/a&gt;.&lt;br /&gt;                How to install Ant will not be covered here. Please refer to the&lt;br /&gt;                &lt;a href="http://ant.apache.org/manual/index.html" target="_top"&gt;Ant manual&lt;/a&gt;. After you&lt;br /&gt;                have installed Ant, we can start to create the buildfile. It will be called&lt;br /&gt;                &lt;tt class="literal"&gt;build.xml&lt;/tt&gt; and placed directly in the development directory.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                A basic build file looks like this:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;project name="hibernate-tutorial" default="compile"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;property name="sourcedir" value="${basedir}/src"/&amp;gt;&lt;br /&gt;    &amp;lt;property name="targetdir" value="${basedir}/bin"/&amp;gt;&lt;br /&gt;    &amp;lt;property name="librarydir" value="${basedir}/lib"/&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;path id="libraries"&amp;gt;&lt;br /&gt;        &amp;lt;fileset dir="${librarydir}"&amp;gt;&lt;br /&gt;            &amp;lt;include name="*.jar"/&amp;gt;&lt;br /&gt;        &amp;lt;/fileset&amp;gt;&lt;br /&gt;    &amp;lt;/path&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;target name="clean"&amp;gt;&lt;br /&gt;        &amp;lt;delete dir="${targetdir}"/&amp;gt;&lt;br /&gt;        &amp;lt;mkdir dir="${targetdir}"/&amp;gt;&lt;br /&gt;    &amp;lt;/target&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;target name="compile" depends="clean, copy-resources"&amp;gt;&lt;br /&gt;      &amp;lt;javac srcdir="${sourcedir}"&lt;br /&gt;             destdir="${targetdir}"&lt;br /&gt;             classpathref="libraries"/&amp;gt;&lt;br /&gt;    &amp;lt;/target&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;target name="copy-resources"&amp;gt;&lt;br /&gt;        &amp;lt;copy todir="${targetdir}"&amp;gt;&lt;br /&gt;            &amp;lt;fileset dir="${sourcedir}"&amp;gt;&lt;br /&gt;                &amp;lt;exclude name="**/*.java"/&amp;gt;&lt;br /&gt;            &amp;lt;/fileset&amp;gt;&lt;br /&gt;        &amp;lt;/copy&amp;gt;&lt;br /&gt;    &amp;lt;/target&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/project&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                This will tell Ant to add all files in the lib directory ending with &lt;tt class="literal"&gt;.jar&lt;/tt&gt;&lt;br /&gt;                to the classpath used for compilation. It will also copy all non-Java source files to the&lt;br /&gt;                target directory, e.g. configuration and Hibernate mapping files. If you now run Ant, you&lt;br /&gt;                should get this output:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;C:\hibernateTutorial\&amp;gt;ant&lt;br /&gt;Buildfile: build.xml&lt;br /&gt;&lt;br /&gt;copy-resources:&lt;br /&gt;     [copy] Copying 2 files to C:\hibernateTutorial\bin&lt;br /&gt;&lt;br /&gt;compile:&lt;br /&gt;    [javac] Compiling 1 source file to C:\hibernateTutorial\bin&lt;br /&gt;&lt;br /&gt;BUILD SUCCESSFUL&lt;br /&gt;Total time: 1 second &lt;/pre&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-firstapp-helpers"&gt;&lt;/a&gt;1.2.5.&amp;nbsp;Startup and helpers&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                It's time to load and store some &lt;tt class="literal"&gt;Event&lt;/tt&gt; objects, but first&lt;br /&gt;                we have to complete the setup with some infrastructure code. We have to startup&lt;br /&gt;                Hibernate. This startup includes building a global &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt;&lt;br /&gt;                object and to store it somewhere for easy access in application code.&lt;br /&gt;                A &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt; can open up new &lt;tt class="literal"&gt;Session&lt;/tt&gt;'s.&lt;br /&gt;                A &lt;tt class="literal"&gt;Session&lt;/tt&gt; represents a single-threaded unit of work, the&lt;br /&gt;                &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt; is a thread-safe global object, instantiated once.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                We'll create a &lt;tt class="literal"&gt;HibernateUtil&lt;/tt&gt; helper class which takes care&lt;br /&gt;                of startup and makes accessing a &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt; convenient.&lt;br /&gt;                Let's have a look at the implementation:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;package util;&lt;br /&gt;&lt;br /&gt;import org.hibernate.*;&lt;br /&gt;import org.hibernate.cfg.*;&lt;br /&gt;&lt;br /&gt;public class HibernateUtil {&lt;br /&gt;&lt;br /&gt;    private static final SessionFactory sessionFactory;&lt;br /&gt;&lt;br /&gt;    static {&lt;br /&gt;        try {&lt;br /&gt;            // Create the SessionFactory from hibernate.cfg.xml&lt;br /&gt;            sessionFactory = new Configuration().configure().buildSessionFactory();&lt;br /&gt;        } catch (Throwable ex) {&lt;br /&gt;            // Make sure you log the exception, as it might be swallowed&lt;br /&gt;            System.err.println("Initial SessionFactory creation failed." + ex);&lt;br /&gt;            throw new ExceptionInInitializerError(ex);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static SessionFactory getSessionFactory() {&lt;br /&gt;        return sessionFactory;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                This class does not only produce the global &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt; in&lt;br /&gt;                its static initializer (called once by the JVM when the class is loaded), but also&lt;br /&gt;                hides the fact that it uses a static singleton. It might as well lookup the&lt;br /&gt;                &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt; from JNDI in an application server.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                If you give the &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt; a name in your configuration&lt;br /&gt;                file, Hibernate will in fact try to bind it to JNDI after it has been built.&lt;br /&gt;                To avoid this code completely you could also use JMX deployment and let the&lt;br /&gt;                JMX-capable container instantiate and bind a &lt;tt class="literal"&gt;HibernateService&lt;/tt&gt;&lt;br /&gt;                to JNDI. These advanced options are discussed in the Hibernate reference&lt;br /&gt;                documentation.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Place &lt;tt class="literal"&gt;HibernateUtil.java&lt;/tt&gt; in the development source directory, in&lt;br /&gt;                a package next to &lt;tt class="literal"&gt;events&lt;/tt&gt;:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;.&lt;br /&gt;+lib&lt;br /&gt;  &amp;lt;Hibernate and third-party libraries&amp;gt;&lt;br /&gt;+src&lt;br /&gt;  +events&lt;br /&gt;    Event.java&lt;br /&gt;    Event.hbm.xml&lt;br /&gt;  +util&lt;br /&gt;    HibernateUtil.java&lt;br /&gt;  hibernate.cfg.xml&lt;br /&gt;+data&lt;br /&gt;build.xml&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                This should again compile without problems. We finally need to configure a logging&lt;br /&gt;                system - Hibernate uses commons logging and leaves you the choice between Log4j and&lt;br /&gt;                JDK 1.4 logging. Most developers prefer Log4j: copy &lt;tt class="literal"&gt;log4j.properties&lt;/tt&gt;&lt;br /&gt;                from the Hibernate distribution (it's in the &lt;tt class="literal"&gt;etc/&lt;/tt&gt; directory) to&lt;br /&gt;                your &lt;tt class="literal"&gt;src&lt;/tt&gt; directory, next to &lt;tt class="literal"&gt;hibernate.cfg.xml&lt;/tt&gt;.&lt;br /&gt;                Have a look at the example configuration and change the settings if you like to have&lt;br /&gt;                more verbose output. By default, only Hibernate startup message are shown on stdout.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                The tutorial infrastructure is complete - and we are ready to do some real work with&lt;br /&gt;                Hibernate.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-firstapp-workingpersistence"&gt;&lt;/a&gt;1.2.6.&amp;nbsp;Loading and storing objects&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                Finally, we can use Hibernate to load and store objects. We write an&lt;br /&gt;                &lt;tt class="literal"&gt;EventManager&lt;/tt&gt; class with a &lt;tt class="literal"&gt;main()&lt;/tt&gt; method:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;package events;&lt;br /&gt;import org.hibernate.Session;&lt;br /&gt;&lt;br /&gt;import java.util.Date;&lt;br /&gt;&lt;br /&gt;import util.HibernateUtil;&lt;br /&gt;&lt;br /&gt;public class EventManager {&lt;br /&gt;&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        EventManager mgr = new EventManager();&lt;br /&gt;&lt;br /&gt;        if (args[0].equals("store")) {&lt;br /&gt;            mgr.createAndStoreEvent("My Event", new Date());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        HibernateUtil.getSessionFactory().close();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;&lt;br /&gt;        Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;&lt;br /&gt;        session.beginTransaction();&lt;br /&gt;&lt;br /&gt;        Event theEvent = new Event();&lt;br /&gt;        theEvent.setTitle(title);&lt;br /&gt;        theEvent.setDate(theDate);&lt;br /&gt;&lt;br /&gt;        session.save(theEvent);&lt;br /&gt;&lt;br /&gt;        session.getTransaction().commit();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                We create a new &lt;tt class="literal"&gt;Event&lt;/tt&gt; object, and hand it over to Hibernate.&lt;br /&gt;                Hibernate now takes care of the SQL and executes &lt;tt class="literal"&gt;INSERT&lt;/tt&gt;s&lt;br /&gt;                on the database. Let's have a look at the &lt;tt class="literal"&gt;Session&lt;/tt&gt; and&lt;br /&gt;                &lt;tt class="literal"&gt;Transaction&lt;/tt&gt;-handling code before we run this.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                A &lt;tt class="literal"&gt;Session&lt;/tt&gt; is a single unit of work. For now we'll keep things&lt;br /&gt;                simple and assume a one-to-one granularity between a Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt;&lt;br /&gt;                and a database transaction. To shield our code from the actual underlying transaction&lt;br /&gt;                system (in this case plain JDBC, but it could also run with JTA) we use the&lt;br /&gt;                &lt;tt class="literal"&gt;Transaction&lt;/tt&gt; API that is available on the Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt;.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                What does &lt;tt class="literal"&gt;sessionFactory.getCurrentSession()&lt;/tt&gt; do? First, you can call it&lt;br /&gt;                as many times and anywhere you like, once you get hold of your &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt;&lt;br /&gt;                (easy thanks to &lt;tt class="literal"&gt;HibernateUtil&lt;/tt&gt;). The &lt;tt class="literal"&gt;getCurrentSession()&lt;/tt&gt;&lt;br /&gt;                method always returns the "current" unit of work. Remember that we switched the configuration&lt;br /&gt;                option for this mechanism to "thread" in &lt;tt class="literal"&gt;hibernate.cfg.xml&lt;/tt&gt;? Hence,&lt;br /&gt;                the current unit of work is bound to the current Java thread that executes our application.&lt;br /&gt;                However, this is not the full picture, you also have to consider scope, when a unit of work&lt;br /&gt;                begins and when it ends.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                A &lt;tt class="literal"&gt;Session&lt;/tt&gt; begins when it is first needed, when the first call to&lt;br /&gt;                &lt;tt class="literal"&gt;getCurrentSession()&lt;/tt&gt; is made. It is then bound by Hibernate to the current&lt;br /&gt;                thread. When the transaction ends, either through commit or rollback, Hibernate automatically&lt;br /&gt;                unbinds the &lt;tt class="literal"&gt;Session&lt;/tt&gt; from the thread and closes it for you. If you call&lt;br /&gt;                &lt;tt class="literal"&gt;getCurrentSession()&lt;/tt&gt; again, you get a new &lt;tt class="literal"&gt;Session&lt;/tt&gt; and can&lt;br /&gt;                start a new unit of work. This &lt;span class="emphasis"&gt;&lt;em&gt;thread-bound&lt;/em&gt;&lt;/span&gt; programming model is the most&lt;br /&gt;                popular way of using Hibernate, as it allows flexible layering of your code (transaction&lt;br /&gt;                demarcation code can be separated from data access code, we'll do this later in this tutorial).&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Related to the unit of work scope, should the Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt; be used to&lt;br /&gt;                execute one or several database operations? The above example uses one &lt;tt class="literal"&gt;Session&lt;/tt&gt;&lt;br /&gt;                for one operation. This is pure coincidence, the example is just not complex enough to show any&lt;br /&gt;                other approach. The scope of a Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt; is flexible but you should&lt;br /&gt;                never design your application to use a new Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt; for&lt;br /&gt;                &lt;span class="emphasis"&gt;&lt;em&gt;every&lt;/em&gt;&lt;/span&gt; database operation. So even if you see it a few more times in&lt;br /&gt;                the following (very trivial) examples, consider &lt;span class="emphasis"&gt;&lt;em&gt;session-per-operation&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;                an anti-pattern. A real (web) application is shown later in this tutorial.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Have a look at &lt;a href="transactions.html" title="Chapter&amp;nbsp;11.&amp;nbsp;Transactions And Concurrency"&gt;Chapter&amp;nbsp;11, &lt;i&gt;Transactions And Concurrency&lt;/i&gt;&lt;/a&gt; for more information&lt;br /&gt;                about transaction handling and demarcation. We also skipped any error handling and&lt;br /&gt;                rollback in the previous example.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                To run this first routine we have to add a callable target to the Ant build file:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;target name="run" depends="compile"&amp;gt;&lt;br /&gt;    &amp;lt;java fork="true" classname="events.EventManager" classpathref="libraries"&amp;gt;&lt;br /&gt;        &amp;lt;classpath path="${targetdir}"/&amp;gt;&lt;br /&gt;        &amp;lt;arg value="${action}"/&amp;gt;&lt;br /&gt;    &amp;lt;/java&amp;gt;&lt;br /&gt;&amp;lt;/target&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                The value of the &lt;tt class="literal"&gt;action&lt;/tt&gt; argument is set on the command line when&lt;br /&gt;                calling the target:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;C:\hibernateTutorial\&amp;gt;ant run -Daction=store&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                You should see, after compilation, Hibernate starting up and, depending on your&lt;br /&gt;                configuration, lots of log output. At the end you will find the following line:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;[java] Hibernate: insert into EVENTS (EVENT_DATE, title, EVENT_ID) values (?, ?, ?)&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                This is the &lt;tt class="literal"&gt;INSERT&lt;/tt&gt; executed by Hibernate, the question marks&lt;br /&gt;                represent JDBC bind parameters. To see the values bound as arguments, or to reduce&lt;br /&gt;                the verbosity of the log, check your &lt;tt class="literal"&gt;log4j.properties&lt;/tt&gt;.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Now we'd like to list stored events as well, so we add an option to the main method:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;if (args[0].equals("store")) {&lt;br /&gt;    mgr.createAndStoreEvent("My Event", new Date());&lt;br /&gt;}&lt;br /&gt;else if (args[0].equals("list")) {&lt;br /&gt;    List events = mgr.listEvents();&lt;br /&gt;    for (int i = 0; i &amp;lt; events.size(); i++) {&lt;br /&gt;        Event theEvent = (Event) events.get(i);&lt;br /&gt;        System.out.println("Event: " + theEvent.getTitle() +&lt;br /&gt;                           " Time: " + theEvent.getDate());&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                We also add a new &lt;tt class="literal"&gt;listEvents() method&lt;/tt&gt;:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;private List listEvents() {&lt;br /&gt;&lt;br /&gt;    Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;&lt;br /&gt;    session.beginTransaction();&lt;br /&gt;&lt;br /&gt;    List result = session.createQuery("from Event").list();&lt;br /&gt;&lt;br /&gt;    session.getTransaction().commit();&lt;br /&gt;&lt;br /&gt;    return result;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                What we do here is use an HQL (Hibernate Query Language) query to load all existing&lt;br /&gt;                &lt;tt class="literal"&gt;Event&lt;/tt&gt; objects from the database. Hibernate will generate the&lt;br /&gt;                appropriate SQL, send it to the database and populate &lt;tt class="literal"&gt;Event&lt;/tt&gt; objects&lt;br /&gt;                with the data. You can create more complex queries with HQL, of course.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Now, to execute and test all of this, follow these steps:&lt;br /&gt;            &lt;/p&gt;&lt;div class="itemizedlist"&gt;&lt;ul type="disc"&gt;&lt;li&gt;&lt;p&gt;&lt;br /&gt;                        Run &lt;tt class="literal"&gt;ant run -Daction=store&lt;/tt&gt; to store something into the database&lt;br /&gt;                        and, of course, to generate the database schema before through hbm2ddl.&lt;br /&gt;                    &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;br /&gt;                        Now disable hbm2ddl by commenting out the property in your &lt;tt class="literal"&gt;hibernate.cfg.xml&lt;/tt&gt;&lt;br /&gt;                        file. Usually you only leave it turned on in continous unit testing, but another&lt;br /&gt;                        run of hbm2ddl would &lt;span class="emphasis"&gt;&lt;em&gt;drop&lt;/em&gt;&lt;/span&gt; everything you have stored - the&lt;br /&gt;                        &lt;tt class="literal"&gt;create&lt;/tt&gt; configuration setting actually translates into "drop all&lt;br /&gt;                        tables from the schema, then re-create all tables, when the SessionFactory is build".&lt;br /&gt;                    &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                If you now call Ant with &lt;tt class="literal"&gt;-Daction=list&lt;/tt&gt;, you should see the events&lt;br /&gt;                you have stored so far. You can of course also call the &lt;tt class="literal"&gt;store&lt;/tt&gt; action a few&lt;br /&gt;                times more.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Note: Most new Hibernate users fail at this point and we see questions about&lt;br /&gt;                &lt;span class="emphasis"&gt;&lt;em&gt;Table not found&lt;/em&gt;&lt;/span&gt; error messages regularly. However, if you follow the&lt;br /&gt;                steps outlined above you will not have this problem, as hbm2ddl creates the database&lt;br /&gt;                schema on the first run, and subsequent application restarts will use this schema. If&lt;br /&gt;                you change the mapping and/or database schema, you have to re-enable hbm2ddl once again.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="sect1" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both"&gt;&lt;a name="tutorial-associations"&gt;&lt;/a&gt;1.3.&amp;nbsp;Part 2 - Mapping associations&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;            We mapped a persistent entity class to a table. Let's build on this and add some class associations.&lt;br /&gt;            First we'll add people to our application, and store a list of events they participate in.&lt;br /&gt;        &lt;/p&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-associations-mappinguser"&gt;&lt;/a&gt;1.3.1.&amp;nbsp;Mapping the Person class&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                The first cut of the &lt;tt class="literal"&gt;Person&lt;/tt&gt; class is simple:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;package events;&lt;br /&gt;&lt;br /&gt;public class Person {&lt;br /&gt;&lt;br /&gt;    private Long id;&lt;br /&gt;    private int age;&lt;br /&gt;    private String firstname;&lt;br /&gt;    private String lastname;&lt;br /&gt;&lt;br /&gt;    public Person() {}&lt;br /&gt;&lt;br /&gt;    // Accessor methods for all properties, private setter for 'id'&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Create a new mapping file called &lt;tt class="literal"&gt;Person.hbm.xml&lt;/tt&gt; (don't forget the&lt;br /&gt;                DTD reference at the top):&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;class name="events.Person" table="PERSON"&amp;gt;&lt;br /&gt;        &amp;lt;id name="id" column="PERSON_ID"&amp;gt;&lt;br /&gt;            &amp;lt;generator class="native"/&amp;gt;&lt;br /&gt;        &amp;lt;/id&amp;gt;&lt;br /&gt;        &amp;lt;property name="age"/&amp;gt;&lt;br /&gt;        &amp;lt;property name="firstname"/&amp;gt;&lt;br /&gt;        &amp;lt;property name="lastname"/&amp;gt;&lt;br /&gt;    &amp;lt;/class&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Finally, add the new mapping to Hibernate's configuration:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;mapping resource="events/Event.hbm.xml"/&amp;gt;&lt;br /&gt;&amp;lt;mapping resource="events/Person.hbm.xml"/&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                We'll now create an association between these two entities. Obviously, persons&lt;br /&gt;                can participate in events, and events have participants. The design questions&lt;br /&gt;                we have to deal with are: directionality, multiplicity, and collection&lt;br /&gt;                behavior.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-associations-unidirset"&gt;&lt;/a&gt;1.3.2.&amp;nbsp;A unidirectional Set-based association&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                We'll add a collection of events to the &lt;tt class="literal"&gt;Person&lt;/tt&gt; class. That way we can&lt;br /&gt;                easily navigate to the events for a particular person, without executing an explicit query -&lt;br /&gt;                by calling &lt;tt class="literal"&gt;aPerson.getEvents()&lt;/tt&gt;. We use a Java collection, a &lt;tt class="literal"&gt;Set&lt;/tt&gt;,&lt;br /&gt;                because the collection will not contain duplicate elements and the ordering is not relevant for us.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                We need a unidirectional, many-valued associations, implemented with a &lt;tt class="literal"&gt;Set&lt;/tt&gt;.&lt;br /&gt;                Let's write the code for this in the Java classes and then map it:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;public class Person {&lt;br /&gt;&lt;br /&gt;    private Set events = new HashSet();&lt;br /&gt;&lt;br /&gt;    public Set getEvents() {&lt;br /&gt;        return events;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setEvents(Set events) {&lt;br /&gt;        this.events = events;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Before we map this association, think about the other side. Clearly, we could just keep this&lt;br /&gt;                unidirectional. Or, we could create another collection on the &lt;tt class="literal"&gt;Event&lt;/tt&gt;, if we&lt;br /&gt;                want to be able to navigate it bi-directional, i.e. &lt;tt class="literal"&gt;anEvent.getParticipants()&lt;/tt&gt;.&lt;br /&gt;                This is not necessary, from a functional perspective. You could always execute an explicit query&lt;br /&gt;                to retrieve the participants for a particular event. This is a design choice left to you, but what&lt;br /&gt;                is clear from this discussion is the multiplicity of the association: "many" valued on both sides,&lt;br /&gt;                we call this a &lt;span class="emphasis"&gt;&lt;em&gt;many-to-many&lt;/em&gt;&lt;/span&gt; association. Hence, we use Hibernate's&lt;br /&gt;                many-to-many mapping:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;class name="events.Person" table="PERSON"&amp;gt;&lt;br /&gt;    &amp;lt;id name="id" column="PERSON_ID"&amp;gt;&lt;br /&gt;        &amp;lt;generator class="native"/&amp;gt;&lt;br /&gt;    &amp;lt;/id&amp;gt;&lt;br /&gt;    &amp;lt;property name="age"/&amp;gt;&lt;br /&gt;    &amp;lt;property name="firstname"/&amp;gt;&lt;br /&gt;    &amp;lt;property name="lastname"/&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;set name="events" table="PERSON_EVENT"&amp;gt;&lt;br /&gt;        &amp;lt;key column="PERSON_ID"/&amp;gt;&lt;br /&gt;        &amp;lt;many-to-many column="EVENT_ID" class="events.Event"/&amp;gt;&lt;br /&gt;    &amp;lt;/set&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Hibernate supports all kinds of collection mappings, a &lt;tt class="literal"&gt;&amp;lt;set&amp;gt;&lt;/tt&gt; being most&lt;br /&gt;                common. For a many-to-many association (or &lt;span class="emphasis"&gt;&lt;em&gt;n:m&lt;/em&gt;&lt;/span&gt; entity relationship), an&lt;br /&gt;                association table is needed. Each row in this table represents a link between a person and an event.&lt;br /&gt;                The table name is configured with the &lt;tt class="literal"&gt;table&lt;/tt&gt; attribute of the &lt;tt class="literal"&gt;set&lt;/tt&gt;&lt;br /&gt;                element. The identifier column name in the association, for the person's side, is defined with the&lt;br /&gt;                &lt;tt class="literal"&gt;&amp;lt;key&amp;gt;&lt;/tt&gt; element, the column name for the event's side with the&lt;br /&gt;                &lt;tt class="literal"&gt;column&lt;/tt&gt; attribute of the &lt;tt class="literal"&gt;&amp;lt;many-to-many&amp;gt;&lt;/tt&gt;. You also&lt;br /&gt;                have to tell Hibernate the class of the objects in your collection (correct: the class on the&lt;br /&gt;                other side of the collection of references).&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                The database schema for this mapping is therefore:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;    _____________        __________________&lt;br /&gt;   |             |      |                  |       _____________&lt;br /&gt;   |   EVENTS    |      |   PERSON_EVENT   |      |             |&lt;br /&gt;   |_____________|      |__________________|      |    PERSON   |&lt;br /&gt;   |             |      |                  |      |_____________|&lt;br /&gt;   | *EVENT_ID   | &amp;lt;--&amp;gt; | *EVENT_ID        |      |             |&lt;br /&gt;   |  EVENT_DATE |      | *PERSON_ID       | &amp;lt;--&amp;gt; | *PERSON_ID  |&lt;br /&gt;   |  TITLE      |      |__________________|      |  AGE        |&lt;br /&gt;   |_____________|                                |  FIRSTNAME  |&lt;br /&gt;                                                  |  LASTNAME   |&lt;br /&gt;                                                  |_____________|&lt;br /&gt; &lt;/pre&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-associations-working"&gt;&lt;/a&gt;1.3.3.&amp;nbsp;Working the association&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                Let's bring some people and events together in a new method in &lt;tt class="literal"&gt;EventManager&lt;/tt&gt;:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;private void addPersonToEvent(Long personId, Long eventId) {&lt;br /&gt;&lt;br /&gt;    Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;    session.beginTransaction();&lt;br /&gt;&lt;br /&gt;    Person aPerson = (Person) session.load(Person.class, personId);&lt;br /&gt;    Event anEvent = (Event) session.load(Event.class, eventId);&lt;br /&gt;&lt;br /&gt;    aPerson.getEvents().add(anEvent);&lt;br /&gt;&lt;br /&gt;    session.getTransaction().commit();&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                After loading a &lt;tt class="literal"&gt;Person&lt;/tt&gt; and an &lt;tt class="literal"&gt;Event&lt;/tt&gt;, simply&lt;br /&gt;                modify the collection using the normal collection methods. As you can see, there is no explicit call&lt;br /&gt;                to &lt;tt class="literal"&gt;update()&lt;/tt&gt; or &lt;tt class="literal"&gt;save()&lt;/tt&gt;, Hibernate automatically&lt;br /&gt;                detects that the collection has been modified and needs to be updated. This is called &lt;span class="emphasis"&gt;&lt;em&gt;automatic&lt;br /&gt;                dirty checking&lt;/em&gt;&lt;/span&gt;, and you can also try it by modifying the name or the date property of&lt;br /&gt;                any of your objects. As long as they are in &lt;span class="emphasis"&gt;&lt;em&gt;persistent&lt;/em&gt;&lt;/span&gt; state, that is, bound&lt;br /&gt;                to a particular Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt; (i.e. they have been just loaded or saved in&lt;br /&gt;                a unit of work), Hibernate monitors any changes and executes SQL in a write-behind fashion. The&lt;br /&gt;                process of synchronizing the memory state with the database, usually only at the end of a unit of&lt;br /&gt;                work, is called &lt;span class="emphasis"&gt;&lt;em&gt;flushing&lt;/em&gt;&lt;/span&gt;. In our code, the unit of work ends with a commit&lt;br /&gt;                (or rollback) of the database transaction - as defined by the &lt;tt class="literal"&gt;thread&lt;/tt&gt; configuration&lt;br /&gt;                option for the &lt;tt class="literal"&gt;CurrentSessionContext&lt;/tt&gt; class.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                You might of course load person and event in different units of work. Or you modify an object&lt;br /&gt;                outside of a &lt;tt class="literal"&gt;Session&lt;/tt&gt;, when it is not in persistent state (if it was persistent&lt;br /&gt;                before, we call this state &lt;span class="emphasis"&gt;&lt;em&gt;detached&lt;/em&gt;&lt;/span&gt;). You can even modify a collection when&lt;br /&gt;                it is detached:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;private void addPersonToEvent(Long personId, Long eventId) {&lt;br /&gt;&lt;br /&gt;    Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;    session.beginTransaction();&lt;br /&gt;&lt;br /&gt;    Person aPerson = (Person) session&lt;br /&gt;            .createQuery("select p from Person p left join fetch p.events where p.id = :pid")&lt;br /&gt;            .setParameter("pid", personId)&lt;br /&gt;            .uniqueResult(); // Eager fetch the collection so we can use it detached&lt;br /&gt;&lt;br /&gt;    Event anEvent = (Event) session.load(Event.class, eventId);&lt;br /&gt;&lt;br /&gt;    session.getTransaction().commit();&lt;br /&gt;&lt;br /&gt;    // End of first unit of work&lt;br /&gt;&lt;br /&gt;    aPerson.getEvents().add(anEvent); // aPerson (and its collection) is detached&lt;br /&gt;&lt;br /&gt;    // Begin second unit of work&lt;br /&gt;&lt;br /&gt;    Session session2 = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;    session2.beginTransaction();&lt;br /&gt;&lt;br /&gt;    session2.update(aPerson); // Reattachment of aPerson&lt;br /&gt;&lt;br /&gt;    session2.getTransaction().commit();&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                The call to &lt;tt class="literal"&gt;update&lt;/tt&gt; makes a detached object persistent again, you could&lt;br /&gt;                say it binds it to a new unit of work, so any modifications you made to it while detached&lt;br /&gt;                can be saved to the database. This includes any modifications (additions/deletions) you&lt;br /&gt;                made to a collection of that entity object.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Well, this is not much use in our current situation, but it's an important concept you can&lt;br /&gt;                design into your own application. For now, complete this exercise by adding a new action&lt;br /&gt;                to the &lt;tt class="literal"&gt;EventManager&lt;/tt&gt;'s main method and call it from the command line. If&lt;br /&gt;                you need the identifiers of a person and an event - the &lt;tt class="literal"&gt;save()&lt;/tt&gt; method&lt;br /&gt;                returns it (you might have to modify some of the previous methods to return that identifier):&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;else if (args[0].equals("addpersontoevent")) {&lt;br /&gt;    Long eventId = mgr.createAndStoreEvent("My Event", new Date());&lt;br /&gt;    Long personId = mgr.createAndStorePerson("Foo", "Bar");&lt;br /&gt;    mgr.addPersonToEvent(personId, eventId);&lt;br /&gt;    System.out.println("Added person " + personId + " to event " + eventId);&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                This was an example of an association between two equally important classes, two entities.&lt;br /&gt;                As mentioned earlier, there are other classes and types in a typical model, usually "less&lt;br /&gt;                important". Some you have already seen, like an &lt;tt class="literal"&gt;int&lt;/tt&gt; or a &lt;tt class="literal"&gt;String&lt;/tt&gt;.&lt;br /&gt;                We call these classes &lt;span class="emphasis"&gt;&lt;em&gt;value types&lt;/em&gt;&lt;/span&gt;, and their instances &lt;span class="emphasis"&gt;&lt;em&gt;depend&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;                on a particular entity. Instances of these types don't have their own identity, nor are they&lt;br /&gt;                shared between entities (two persons don't reference the same &lt;tt class="literal"&gt;firstname&lt;/tt&gt;&lt;br /&gt;                object, even if they have the same first name). Of course, value types can not only be found in&lt;br /&gt;                the JDK (in fact, in a Hibernate application all JDK classes are considered value types), but&lt;br /&gt;                you can also write dependent classes yourself, &lt;tt class="literal"&gt;Address&lt;/tt&gt; or &lt;tt class="literal"&gt;MonetaryAmount&lt;/tt&gt;,&lt;br /&gt;                for example.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                You can also design a collection of value types. This is conceptually very different from a&lt;br /&gt;                collection of references to other entities, but looks almost the same in Java.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-associations-valuecollections"&gt;&lt;/a&gt;1.3.4.&amp;nbsp;Collection of values&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                We add a collection of value typed objects to the &lt;tt class="literal"&gt;Person&lt;/tt&gt; entity. We want to&lt;br /&gt;                store email addresses, so the type we use is &lt;tt class="literal"&gt;String&lt;/tt&gt;, and the collection is&lt;br /&gt;                again a &lt;tt class="literal"&gt;Set&lt;/tt&gt;:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;private Set emailAddresses = new HashSet();&lt;br /&gt;&lt;br /&gt;public Set getEmailAddresses() {&lt;br /&gt;    return emailAddresses;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setEmailAddresses(Set emailAddresses) {&lt;br /&gt;    this.emailAddresses = emailAddresses;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                The mapping of this &lt;tt class="literal"&gt;Set&lt;/tt&gt;:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;set name="emailAddresses" table="PERSON_EMAIL_ADDR"&amp;gt;&lt;br /&gt;    &amp;lt;key column="PERSON_ID"/&amp;gt;&lt;br /&gt;    &amp;lt;element type="string" column="EMAIL_ADDR"/&amp;gt;&lt;br /&gt;&amp;lt;/set&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                The difference compared with the earlier mapping is the &lt;tt class="literal"&gt;element&lt;/tt&gt; part, which tells Hibernate that the collection&lt;br /&gt;                does not contain references to another entity, but a collection of elements of type&lt;br /&gt;                &lt;tt class="literal"&gt;String&lt;/tt&gt; (the lowercase name tells you it's a Hibernate mapping type/converter).&lt;br /&gt;                Once again, the &lt;tt class="literal"&gt;table&lt;/tt&gt; attribute of the &lt;tt class="literal"&gt;set&lt;/tt&gt; element determines&lt;br /&gt;                the table name for the collection. The &lt;tt class="literal"&gt;key&lt;/tt&gt; element defines the foreign-key column&lt;br /&gt;                name in the collection table. The &lt;tt class="literal"&gt;column&lt;/tt&gt; attribute in the &lt;tt class="literal"&gt;element&lt;/tt&gt;&lt;br /&gt;                element defines the column name where the &lt;tt class="literal"&gt;String&lt;/tt&gt; values will actually be stored.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Have a look at the updated schema:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;  _____________        __________________&lt;br /&gt; |             |      |                  |       _____________&lt;br /&gt; |   EVENTS    |      |   PERSON_EVENT   |      |             |       ___________________&lt;br /&gt; |_____________|      |__________________|      |    PERSON   |      |                   |&lt;br /&gt; |             |      |                  |      |_____________|      | PERSON_EMAIL_ADDR |&lt;br /&gt; | *EVENT_ID   | &amp;lt;--&amp;gt; | *EVENT_ID        |      |             |      |___________________|&lt;br /&gt; |  EVENT_DATE |      | *PERSON_ID       | &amp;lt;--&amp;gt; | *PERSON_ID  | &amp;lt;--&amp;gt; |  *PERSON_ID       |&lt;br /&gt; |  TITLE      |      |__________________|      |  AGE        |      |  *EMAIL_ADDR      |&lt;br /&gt; |_____________|                                |  FIRSTNAME  |      |___________________|&lt;br /&gt;                                                |  LASTNAME   |&lt;br /&gt;                                                |_____________|&lt;br /&gt; &lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                You can see that the primary key of the collection table is in fact a composite key,&lt;br /&gt;                using both columns. This also implies that there can't be duplicate email addresses&lt;br /&gt;                per person, which is exactly the semantics we need for a set in Java.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                You can now try and add elements to this collection, just like we did before by&lt;br /&gt;                linking persons and events. It's the same code in Java:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;private void addEmailToPerson(Long personId, String emailAddress) {&lt;br /&gt;&lt;br /&gt;    Session session = HibernateUtil.getSessionFactory().getCurrentSession();&lt;br /&gt;    session.beginTransaction();&lt;br /&gt;&lt;br /&gt;    Person aPerson = (Person) session.load(Person.class, personId);&lt;br /&gt;&lt;br /&gt;    // The getEmailAddresses() might trigger a lazy load of the collection&lt;br /&gt;    aPerson.getEmailAddresses().add(emailAddress);&lt;br /&gt;&lt;br /&gt;    session.getTransaction().commit();&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                This time we didnt' use a &lt;span class="emphasis"&gt;&lt;em&gt;fetch&lt;/em&gt;&lt;/span&gt; query to initialize the collection.&lt;br /&gt;                Hence, the call to its getter method will trigger an additional select to initialize&lt;br /&gt;                it, so we can add an element to it. Monitor the SQL log and try to optimize this with&lt;br /&gt;                an eager fetch.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-associations-bidirectional"&gt;&lt;/a&gt;1.3.5.&amp;nbsp;Bi-directional associations&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                Next we are going to map a bi-directional association - making the association between&lt;br /&gt;                person and event work from both sides in Java. Of course, the database schema doesn't&lt;br /&gt;                change, we still have many-to-many multiplicity. A relational database is more flexible&lt;br /&gt;                than a network programming language, so it doesn't need anything like a navigation&lt;br /&gt;                direction - data can be viewed and retrieved in any possible way.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                First, add a collection of participants to the &lt;tt class="literal"&gt;Event&lt;/tt&gt; Event class:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;private Set participants = new HashSet();&lt;br /&gt;&lt;br /&gt;public Set getParticipants() {&lt;br /&gt;    return participants;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setParticipants(Set participants) {&lt;br /&gt;    this.participants = participants;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Now map this side of the association too, in &lt;tt class="literal"&gt;Event.hbm.xml&lt;/tt&gt;.&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;set name="participants" table="PERSON_EVENT" inverse="true"&amp;gt;&lt;br /&gt;    &amp;lt;key column="EVENT_ID"/&amp;gt;&lt;br /&gt;    &amp;lt;many-to-many column="PERSON_ID" class="events.Person"/&amp;gt;&lt;br /&gt;&amp;lt;/set&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                As you see, these are normal &lt;tt class="literal"&gt;set&lt;/tt&gt; mappings in both mapping documents.&lt;br /&gt;                Notice that the column names in &lt;tt class="literal"&gt;key&lt;/tt&gt; and &lt;tt class="literal"&gt;many-to-many&lt;/tt&gt; are&lt;br /&gt;                swapped in both mapping documents. The most important addition here is the&lt;br /&gt;                &lt;tt class="literal"&gt;inverse="true"&lt;/tt&gt; attribute in the &lt;tt class="literal"&gt;set&lt;/tt&gt; element of the&lt;br /&gt;                &lt;tt class="literal"&gt;Event&lt;/tt&gt;'s collection mapping.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                What this means is that Hibernate should take the other side - the &lt;tt class="literal"&gt;Person&lt;/tt&gt; class -&lt;br /&gt;                when it needs to find out information about the link between the two. This will be a lot easier to&lt;br /&gt;                understand once you see how the bi-directional link between our two entities is created .&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-associations-usingbidir"&gt;&lt;/a&gt;1.3.6.&amp;nbsp;Working bi-directional links&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                First, keep in mind that Hibernate does not affect normal Java semantics. How did we create a&lt;br /&gt;                link between a &lt;tt class="literal"&gt;Person&lt;/tt&gt; and an &lt;tt class="literal"&gt;Event&lt;/tt&gt; in the unidirectional&lt;br /&gt;                example? We added an instance of &lt;tt class="literal"&gt;Event&lt;/tt&gt; to the collection of event references,&lt;br /&gt;                of an instance of &lt;tt class="literal"&gt;Person&lt;/tt&gt;. So, obviously, if we want to make this link working&lt;br /&gt;                bi-directional, we have to do the same on the other side - adding a &lt;tt class="literal"&gt;Person&lt;/tt&gt;&lt;br /&gt;                reference to the collection in an &lt;tt class="literal"&gt;Event&lt;/tt&gt;. This "setting the link on both sides"&lt;br /&gt;                is absolutely necessary and you should never forget doing it.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Many developers program defensive and create a link management methods to&lt;br /&gt;                correctly set both sides, e.g. in &lt;tt class="literal"&gt;Person&lt;/tt&gt;:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;protected Set getEvents() {&lt;br /&gt;    return events;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void setEvents(Set events) {&lt;br /&gt;    this.events = events;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void addToEvent(Event event) {&lt;br /&gt;    this.getEvents().add(event);&lt;br /&gt;    event.getParticipants().add(this);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void removeFromEvent(Event event) {&lt;br /&gt;    this.getEvents().remove(event);&lt;br /&gt;    event.getParticipants().remove(this);&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Notice that the get and set methods for the collection are now protected - this allows classes in the&lt;br /&gt;                same package and subclasses to still access the methods, but prevents everybody else from messing&lt;br /&gt;                with the collections directly (well, almost). You should probably do the same with the collection&lt;br /&gt;                on the other side.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                What about the &lt;tt class="literal"&gt;inverse&lt;/tt&gt; mapping attribute? For you, and for Java, a bi-directional&lt;br /&gt;                link is simply a matter of setting the references on both sides correctly. Hibernate however doesn't&lt;br /&gt;                have enough information to correctly arrange SQL &lt;tt class="literal"&gt;INSERT&lt;/tt&gt; and &lt;tt class="literal"&gt;UPDATE&lt;/tt&gt;&lt;br /&gt;                statements (to avoid constraint violations), and needs some help to handle bi-directional associations&lt;br /&gt;                properly. Making one side of the association &lt;tt class="literal"&gt;inverse&lt;/tt&gt; tells Hibernate to basically&lt;br /&gt;                ignore it, to consider it a &lt;span class="emphasis"&gt;&lt;em&gt;mirror&lt;/em&gt;&lt;/span&gt; of the other side. That's all that is necessary&lt;br /&gt;                for Hibernate to work out all of the issues when transformation a directional navigation model to&lt;br /&gt;                a SQL database schema. The rules you have to remember are straightforward: All bi-directional associations&lt;br /&gt;                need one side as &lt;tt class="literal"&gt;inverse&lt;/tt&gt;. In a one-to-many association it has to be the many-side,&lt;br /&gt;                in many-to-many association you can pick either side, there is no difference.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;            Let's turn this into a small web application.&lt;br /&gt;        &lt;/p&gt;&lt;/div&gt;&lt;div class="sect1" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both"&gt;&lt;a name="tutorial-webapp"&gt;&lt;/a&gt;1.4.&amp;nbsp;Part 3 - The EventManager web application&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;            A Hibernate web application uses &lt;tt class="literal"&gt;Session&lt;/tt&gt; and &lt;tt class="literal"&gt;Transaction&lt;/tt&gt;&lt;br /&gt;            almost like a standalone application. However, some common patterns are useful. We now write&lt;br /&gt;            an &lt;tt class="literal"&gt;EventManagerServlet&lt;/tt&gt;. This servlet can list all events stored in the&lt;br /&gt;            database, and it provides an HTML form to enter new events.&lt;br /&gt;        &lt;/p&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-webapp-servlet"&gt;&lt;/a&gt;1.4.1.&amp;nbsp;Writing the basic servlet&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                Create a new class in your source directory, in the &lt;tt class="literal"&gt;events&lt;/tt&gt;&lt;br /&gt;                package:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;package events;&lt;br /&gt;&lt;br /&gt;// Imports&lt;br /&gt;&lt;br /&gt;public class EventManagerServlet extends HttpServlet {&lt;br /&gt;&lt;br /&gt;    // Servlet code&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                The servlet handles HTTP &lt;tt class="literal"&gt;GET&lt;/tt&gt; requests only, hence, the method&lt;br /&gt;                we implement is &lt;tt class="literal"&gt;doGet()&lt;/tt&gt;:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;protected void doGet(HttpServletRequest request,&lt;br /&gt;                     HttpServletResponse response)&lt;br /&gt;        throws ServletException, IOException {&lt;br /&gt;&lt;br /&gt;    SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy");&lt;br /&gt;&lt;br /&gt;    try {&lt;br /&gt;        // Begin unit of work&lt;br /&gt;        HibernateUtil.getSessionFactory()&lt;br /&gt;                .getCurrentSession().beginTransaction();&lt;br /&gt;&lt;br /&gt;        // Process request and render page...&lt;br /&gt;&lt;br /&gt;        // End unit of work&lt;br /&gt;        HibernateUtil.getSessionFactory()&lt;br /&gt;                .getCurrentSession().getTransaction().commit();&lt;br /&gt;&lt;br /&gt;    } catch (Exception ex) {&lt;br /&gt;        HibernateUtil.getSessionFactory()&lt;br /&gt;                .getCurrentSession().getTransaction().rollback();&lt;br /&gt;        throw new ServletException(ex);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                The pattern we are applying here is called &lt;span class="emphasis"&gt;&lt;em&gt;session-per-request&lt;/em&gt;&lt;/span&gt;.&lt;br /&gt;                When a request hits the servlet, a new Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt; is&lt;br /&gt;                opened through the first call to &lt;tt class="literal"&gt;getCurrentSession()&lt;/tt&gt; on the&lt;br /&gt;                &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt;. Then a database transaction is started&amp;#8212;all&lt;br /&gt;                data access as to occur inside a transaction, no matter if data is read or written&lt;br /&gt;                (we don't use the auto-commit mode in applications).&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Do &lt;span class="emphasis"&gt;&lt;em&gt;not&lt;/em&gt;&lt;/span&gt; use a new Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt; for&lt;br /&gt;                every database operation. Use one Hibernate &lt;tt class="literal"&gt;Session&lt;/tt&gt; that is&lt;br /&gt;                scoped to the whole request. Use &lt;tt class="literal"&gt;getCurrentSession()&lt;/tt&gt;, so that&lt;br /&gt;                it is automatically bound to the current Java thread.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Next, the possible actions of the request are processed and the response HTML&lt;br /&gt;                is rendered. We'll get to that part soon.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Finally, the unit of work ends when processing and rendering is complete. If any&lt;br /&gt;                problem occured during processing or rendering, an exception will be thrown&lt;br /&gt;                and the database transaction rolled back. This completes the&lt;br /&gt;                &lt;tt class="literal"&gt;session-per-request&lt;/tt&gt; pattern. Instead of the transaction&lt;br /&gt;                demarcation code in every servlet you could also write a servlet filter.&lt;br /&gt;                See the Hibernate website and Wiki for more information about this pattern,&lt;br /&gt;                called &lt;span class="emphasis"&gt;&lt;em&gt;Open Session in View&lt;/em&gt;&lt;/span&gt;&amp;#8212;you'll need it as soon&lt;br /&gt;                as you consider rendering your view in JSP, not in a servlet.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-webapp-processing"&gt;&lt;/a&gt;1.4.2.&amp;nbsp;Processing and rendering&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                Let's implement the processing of the request and rendering of the page.&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;// Write HTML header&lt;br /&gt;PrintWriter out = response.getWriter();&lt;br /&gt;out.println("&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Event Manager&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;");&lt;br /&gt;&lt;br /&gt;// Handle actions&lt;br /&gt;if ( "store".equals(request.getParameter("action")) ) {&lt;br /&gt;&lt;br /&gt;    String eventTitle = request.getParameter("eventTitle");&lt;br /&gt;    String eventDate = request.getParameter("eventDate");&lt;br /&gt;&lt;br /&gt;    if ( "".equals(eventTitle) || "".equals(eventDate) ) {&lt;br /&gt;        out.println("&amp;lt;b&amp;gt;&amp;lt;i&amp;gt;Please enter event title and date.&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;");&lt;br /&gt;    } else {&lt;br /&gt;        createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));&lt;br /&gt;        out.println("&amp;lt;b&amp;gt;&amp;lt;i&amp;gt;Added event.&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Print page&lt;br /&gt;printEventForm(out);&lt;br /&gt;listEvents(out, dateFormatter);&lt;br /&gt;&lt;br /&gt;// Write HTML footer&lt;br /&gt;out.println("&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");&lt;br /&gt;out.flush();&lt;br /&gt;out.close();&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Granted, this coding style with a mix of Java and HTML would not scale&lt;br /&gt;                in a more complex application&amp;#8212;keep in mind that we are only illustrating&lt;br /&gt;                basic Hibernate concepts in this tutorial. The code prints an HTML&lt;br /&gt;                header and a footer. Inside this page, an HTML form for event entry and&lt;br /&gt;                a list of all events in the database are printed. The first method is&lt;br /&gt;                trivial and only outputs HTML:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;private void printEventForm(PrintWriter out) {&lt;br /&gt;    out.println("&amp;lt;h2&amp;gt;Add new event:&amp;lt;/h2&amp;gt;");&lt;br /&gt;    out.println("&amp;lt;form&amp;gt;");&lt;br /&gt;    out.println("Title: &amp;lt;input name='eventTitle' length='50'/&amp;gt;&amp;lt;br/&amp;gt;");&lt;br /&gt;    out.println("Date (e.g. 24.12.2009): &amp;lt;input name='eventDate' length='10'/&amp;gt;&amp;lt;br/&amp;gt;");&lt;br /&gt;    out.println("&amp;lt;input type='submit' name='action' value='store'/&amp;gt;");&lt;br /&gt;    out.println("&amp;lt;/form&amp;gt;");&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                The &lt;tt class="literal"&gt;listEvents()&lt;/tt&gt; method uses the Hibernate&lt;br /&gt;                &lt;tt class="literal"&gt;Session&lt;/tt&gt; bound to the current thread to execute&lt;br /&gt;                a query:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;private void listEvents(PrintWriter out, SimpleDateFormat dateFormatter) {&lt;br /&gt;&lt;br /&gt;    List result = HibernateUtil.getSessionFactory()&lt;br /&gt;                    .getCurrentSession().createCriteria(Event.class).list();&lt;br /&gt;    if (result.size() &amp;gt; 0) {&lt;br /&gt;        out.println("&amp;lt;h2&amp;gt;Events in database:&amp;lt;/h2&amp;gt;");&lt;br /&gt;        out.println("&amp;lt;table border='1'&amp;gt;");&lt;br /&gt;        out.println("&amp;lt;tr&amp;gt;");&lt;br /&gt;        out.println("&amp;lt;th&amp;gt;Event title&amp;lt;/th&amp;gt;");&lt;br /&gt;        out.println("&amp;lt;th&amp;gt;Event date&amp;lt;/th&amp;gt;");&lt;br /&gt;        out.println("&amp;lt;/tr&amp;gt;");&lt;br /&gt;        for (Iterator it = result.iterator(); it.hasNext();) {&lt;br /&gt;            Event event = (Event) it.next();&lt;br /&gt;            out.println("&amp;lt;tr&amp;gt;");&lt;br /&gt;            out.println("&amp;lt;td&amp;gt;" + event.getTitle() + "&amp;lt;/td&amp;gt;");&lt;br /&gt;            out.println("&amp;lt;td&amp;gt;" + dateFormatter.format(event.getDate()) + "&amp;lt;/td&amp;gt;");&lt;br /&gt;            out.println("&amp;lt;/tr&amp;gt;");&lt;br /&gt;        }&lt;br /&gt;        out.println("&amp;lt;/table&amp;gt;");&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Finally, the &lt;tt class="literal"&gt;store&lt;/tt&gt; action is dispatched to the&lt;br /&gt;                &lt;tt class="literal"&gt;createAndStoreEvent()&lt;/tt&gt; method, which also uses&lt;br /&gt;                the &lt;tt class="literal"&gt;Session&lt;/tt&gt; of the current thread:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;protected void createAndStoreEvent(String title, Date theDate) {&lt;br /&gt;    Event theEvent = new Event();&lt;br /&gt;    theEvent.setTitle(title);&lt;br /&gt;    theEvent.setDate(theDate);&lt;br /&gt;&lt;br /&gt;    HibernateUtil.getSessionFactory()&lt;br /&gt;                    .getCurrentSession().save(theEvent);&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                That's it, the servlet is complete. A request to the servlet will be processed&lt;br /&gt;                in a single &lt;tt class="literal"&gt;Session&lt;/tt&gt; and &lt;tt class="literal"&gt;Transaction&lt;/tt&gt;. As&lt;br /&gt;                earlier in the standalone application, Hibernate can automatically bind these&lt;br /&gt;                ojects to the current thread of execution. This gives you the freedom to layer&lt;br /&gt;                your code and access the &lt;tt class="literal"&gt;SessionFactory&lt;/tt&gt; in any way you like.&lt;br /&gt;                Usually you'd use a more sophisticated design and move the data access code&lt;br /&gt;                into data access objects (the DAO pattern). See the Hibernate Wiki for more&lt;br /&gt;                examples.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;div class="sect2" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h3 class="title"&gt;&lt;a name="tutorial-webapp-deploy"&gt;&lt;/a&gt;1.4.3.&amp;nbsp;Deploying and testing&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;                To deploy this application you have to create a web archive, a WAR. Add the&lt;br /&gt;                following Ant target to your &lt;tt class="literal"&gt;build.xml&lt;/tt&gt;:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;target name="war" depends="compile"&amp;gt;&lt;br /&gt;    &amp;lt;war destfile="hibernate-tutorial.war" webxml="web.xml"&amp;gt;&lt;br /&gt;        &amp;lt;lib dir="${librarydir}"&amp;gt;&lt;br /&gt;          &amp;lt;exclude name="jsdk*.jar"/&amp;gt;&lt;br /&gt;        &amp;lt;/lib&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;classes dir="${targetdir}"/&amp;gt;&lt;br /&gt;    &amp;lt;/war&amp;gt;&lt;br /&gt;&amp;lt;/target&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                This target creates a file called &lt;tt class="literal"&gt;hibernate-tutorial.war&lt;/tt&gt;&lt;br /&gt;                in your project directory. It packages all libraries and the &lt;tt class="literal"&gt;web.xml&lt;/tt&gt;&lt;br /&gt;                descriptor, which is expected in the base directory of your project:&lt;br /&gt;            &lt;/p&gt;&lt;pre class="programlisting"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;web-app version="2.4"&lt;br /&gt;    xmlns="http://java.sun.com/xml/ns/j2ee"&lt;br /&gt;    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt;    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;servlet&amp;gt;&lt;br /&gt;        &amp;lt;servlet-name&amp;gt;Event Manager&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;        &amp;lt;servlet-class&amp;gt;events.EventManagerServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;    &amp;lt;/servlet&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;        &amp;lt;servlet-name&amp;gt;Event Manager&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;        &amp;lt;url-pattern&amp;gt;/eventmanager&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;    &amp;lt;/servlet-mapping&amp;gt;&lt;br /&gt;&amp;lt;/web-app&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;                Before you compile and deploy the web application, note that an additional library&lt;br /&gt;                is required: &lt;tt class="literal"&gt;jsdk.jar&lt;/tt&gt;. This is the Java servlet development kit,&lt;br /&gt;                if you don't have this library already, get it from the Sun website and copy it to&lt;br /&gt;                your library directory. However, it will be only used for compliation and excluded&lt;br /&gt;                from the WAR package.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                To build and deploy call &lt;tt class="literal"&gt;ant war&lt;/tt&gt; in your project directory&lt;br /&gt;                and copy the &lt;tt class="literal"&gt;hibernate-tutorial.war&lt;/tt&gt; file into your Tomcat&lt;br /&gt;                &lt;tt class="literal"&gt;webapp&lt;/tt&gt; directory. If you don't have Tomcat installed, download&lt;br /&gt;                it and follow the installation instructions. You don't have to change any Tomcat&lt;br /&gt;                configuration to deploy this application though.&lt;br /&gt;            &lt;/p&gt;&lt;p&gt;&lt;br /&gt;                Once deployed and Tomcat is running, access the application at&lt;br /&gt;                &lt;tt class="literal"&gt;http://localhost:8080/hibernate-tutorial/eventmanager&lt;/tt&gt;. Make&lt;br /&gt;                sure you watch the Tomcat log to see Hibernate initialize when the first&lt;br /&gt;                request hits your servlet (the static initializer in &lt;tt class="literal"&gt;HibernateUtil&lt;/tt&gt;&lt;br /&gt;                is called) and to get the detailed output if any exceptions occurs.&lt;br /&gt;            &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="sect1" lang="en"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both"&gt;&lt;a name="tutorial-summary"&gt;&lt;/a&gt;1.5.&amp;nbsp;Summary&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;            This tutorial covered the basics of writing a simple standalone Hibernate application&lt;br /&gt;            and a small web application.&lt;br /&gt;        &lt;/p&gt;&lt;p&gt;&lt;br /&gt;            If you already feel confident with Hibernate, continue browsing through the reference&lt;br /&gt;            documentation table of contents for topics you find interesting - most asked are&lt;br /&gt;            transactional processing (&lt;a href="transactions.html" title="Chapter&amp;nbsp;11.&amp;nbsp;Transactions And Concurrency"&gt;Chapter&amp;nbsp;11, &lt;i&gt;Transactions And Concurrency&lt;/i&gt;&lt;/a&gt;), fetch&lt;br /&gt;            performance (&lt;a href="performance.html" title="Chapter&amp;nbsp;19.&amp;nbsp;Improving performance"&gt;Chapter&amp;nbsp;19, &lt;i&gt;Improving performance&lt;/i&gt;&lt;/a&gt;), or the usage of the API (&lt;a href="objectstate.html" title="Chapter&amp;nbsp;10.&amp;nbsp;Working with objects"&gt;Chapter&amp;nbsp;10, &lt;i&gt;Working with objects&lt;/i&gt;&lt;/a&gt;)&lt;br /&gt;            and the query features (&lt;a href="objectstate.html#objectstate-querying" title="10.4.&amp;nbsp;Querying"&gt;Section&amp;nbsp;10.4, &amp;#8220;Querying&amp;#8221;&lt;/a&gt;).&lt;br /&gt;        &lt;/p&gt;&lt;p&gt;&lt;br /&gt;            Don't forget to check the Hibernate website for more (specialized) tutorials.&lt;br /&gt;        &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-2997186271524873910?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/2997186271524873910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=2997186271524873910' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/2997186271524873910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/2997186271524873910'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/07/hibernate-relational-persistence-for.html' title='HIBERNATE - Relational Persistence for Idiomatic Java'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-4452946104639182169</id><published>2007-07-24T07:03:00.000-07:00</published><updated>2007-07-27T07:42:45.243-07:00</updated><title type='text'>Useful URLsfor Freshers</title><content type='html'>&lt;a href="www.naukri.com" target="_blank"&gt;www.naukri.com&lt;/a&gt;&lt;br /&gt;&lt;a href="www.jobsassist.com" target="_blank"&gt;www.jobsassist.com&lt;/a&gt;&lt;br /&gt;&lt;a href="www.jobstreet.com" target="_blank"&gt;www.jobstreet.com&lt;/a&gt;&lt;br /&gt;&lt;a href="www.monster.com" target="_blank"&gt;www.monster.com&lt;/a&gt;&lt;br /&gt;&lt;a href="www.jobsahead.com" target="_blank"&gt;www.jobsahead.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="www.sansite.com" target="_blank"&gt;www.sansite.com&lt;/a&gt;&lt;br /&gt;&lt;a href="www.efreshers.com" target="_blank"&gt;www.efreshers.com&lt;/a&gt;&lt;br /&gt;&lt;a href="www.todaysfresher.com" target="_blank"&gt;www.todaysfresher.com&lt;/a&gt;&lt;br /&gt;&lt;a href="www.careermirchi.com" target="_blank"&gt;www.careermirchi.com&lt;/a&gt;&lt;br /&gt;&lt;a href="www.chetanafresherjobs.com" target="_blank"&gt;www.chetanafresherjobs.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;www.fresherstreet. com&lt;br /&gt;www.freshersworld.com&lt;br /&gt;www.haikeralam.com&lt;br /&gt;www.yuvajobs.com&lt;br /&gt;www.mindjobs.com&lt;br /&gt;www.chetanaS.com&lt;br /&gt;www.careerenclave.com&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-4452946104639182169?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/4452946104639182169/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=4452946104639182169' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4452946104639182169'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4452946104639182169'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/07/useful-links-for-freshers.html' title='Useful URLsfor Freshers'/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6615883157507452442.post-4590813262074983771</id><published>2007-07-21T21:38:00.000-07:00</published><updated>2007-07-27T07:42:07.379-07:00</updated><title type='text'></title><content type='html'>Starting point for Sun's Java technology certification.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.enterprisedeveloper.com/jcertify/"&gt;JCertify&lt;/a&gt; - http://www.enterprisedeveloper.com/jcertify/ Java Certification exam simulator with tutorials and integrated training content. [Commercial]&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.whizlabs.com/jwhiz.html"&gt;Whizlabs&lt;/a&gt; - http://www.whizlabs.com/jwhiz.html Provides exam simulators and online training for Sun Java Certification exams: SCJP, SCWCD, SCBCD and SCEA [Commercial].&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.levteck.com/"&gt;Levteck.com&lt;/a&gt; - http://www.levteck.com/ Includes list of certification books, study aides, links for mock exams and salary surveys.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www-106.ibm.com/developerworks/edu/j-dw-java-scjp-i.html"&gt;Java certification success, Part 1: SCJP&lt;/a&gt; - http://www-106.ibm.com/developerworks/edu/j-dw-java-scjp-i.html A tutorial designed to prepare programmers for SCJP 1.4 exam, providing a detailed overview of the exam's main objectives.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.jchq.net/"&gt;Marcus Green's Java Certification&lt;/a&gt; - http://www.jchq.net/ SCJP exam resource with tutorials, mock exam and community features.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/wahjava/"&gt;Wah! Java&lt;/a&gt; - http://www.geocities.com/wahjava/ Contains topic-wise mock tests, tips from those who passed, recommended books and links to other testing/java resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javaprepare.com/"&gt;JavaPrepare&lt;/a&gt; - http://www.javaprepare.com/ Tutorials, mock exams and other preparation material for SCJP and SCWCD.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://groups.yahoo.com/group/javacertstudy/"&gt;Java Certification Study Group&lt;/a&gt; - http://groups.yahoo.com/group/javacertstudy/ Study community with forums, chat and resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://resources.corejsp.com/scwcd.html"&gt;SCWCD Certification Resources&lt;/a&gt; - http://resources.corejsp.com/scwcd.html Contains links to study guides, exam simulators and other resources for SCWCD examination.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://courses.coreservlets.com/Course-Materials/pdf/msajsp/15-Web-Component-Certification.pdf"&gt;SCWCD Exam Review&lt;/a&gt; - http://courses.coreservlets.com/Course-Materials/pdf/msajsp/15-Web-Component-Certification.pdf Review notes for the Sun Certified Web Component Developer exam.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.danchisholm.net/"&gt;Certified Java Programmer Mock Exam (310-025, 310-035)&lt;/a&gt; - http://www.danchisholm.net/ Contains mock exams and tutorials for SCJP exam.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.absolutejava.com/"&gt;Absolute Java&lt;/a&gt; - http://www.absolutejava.com/ Collection of tidbits to prepare for SCJP exam.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.jiris.com/"&gt;Jiris&lt;/a&gt; - http://www.jiris.com/ Contains mock exams, links, forum, code examples and other SCJP/SCWCD resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javacertificate.com/"&gt;JavaCertificate&lt;/a&gt; - http://www.javacertificate.com/ A free online training centre that will help prepare for the Sun Certified Programmer for Java(tm) 2 Platform exam (SCJP 1.4).&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.anilbachi.8m.com/"&gt;Anilbachi Java Certification Resources&lt;/a&gt; - http://www.anilbachi.8m.com/ SCJP tutorial, mock exams, objectives, mock exam links and discussion forum.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.whizlabs.com/tutorial/scjp/index.html"&gt;Java certification success, Part 1: SCJP&lt;/a&gt; - http://www.whizlabs.com/tutorial/scjp/index.html A SCJP Tutorial to test the knowledge of Java fundamentals and requires in-depth knowledge of the syntax and semantics.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.aniyog.com/java/certification.htm"&gt;Certification: The Java Mock Test&lt;/a&gt; - http://www.aniyog.com/java/certification.htm Offers free applet based mock exam for SCJP2.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.akgupta.com/Java/certification.htm"&gt;Java Certification (SCJP)&lt;/a&gt; - http://www.akgupta.com/Java/certification.htm Contains SCJP mock exam, tidbits, exam notes and links to other resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/velmurugan_p/"&gt;Java Certification Study Notes&lt;/a&gt; - http://www.geocities.com/velmurugan_p/ SCJP &amp; SCWCD study notes, resources and tips.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.jguru.com/forums/JavaCertification"&gt;Java Guru: Java Certification Forum Home Page&lt;/a&gt; - http://www.jguru.com/forums/JavaCertification Forum to pose and view the who, what, where, why and how questions on Java certification.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/sunjava4u/"&gt;Sun Java 4 U&lt;/a&gt; - http://www.geocities.com/sunjava4u/ Links and resources useful for SCJP aspirants includes exam simulators, mock exams, study guides.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://java.certifiedprogrammer.com/"&gt;Java.CertifiedProgrammer.com&lt;/a&gt; - http://java.certifiedprogrammer.com/ Contains study aides, news and mock exams.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.acmerocket.com/skinny/"&gt;The Java Skinny&lt;/a&gt; - http://www.acmerocket.com/skinny/ Contains sample questions, SCJP exam objectives with code examples and other resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/skmajji/Main.html"&gt;Sun Certified Java Programmer sample test paper!&lt;/a&gt; - http://www.geocities.com/skmajji/Main.html A practice test for SCJP comprising of 30 questions with answers.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.enthuware.com/"&gt;Enthuware&lt;/a&gt; - http://www.enthuware.com/ Test simulators for Sun certification exams. [Commercial]&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.janeg.ca/index.html"&gt;Java Quick Reference&lt;/a&gt; - http://www.janeg.ca/index.html Comprises of concise study notes for SCJP exam and other links.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javabeat.net/"&gt;JavaBeat&lt;/a&gt; - http://www.javabeat.net/ Java certification resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://certification.about.com/cs/freequestions/index.htm"&gt;About.com - Java Certifications&lt;/a&gt; - http://certification.about.com/cs/freequestions/index.htm Explore information and links for Java and Sun certifications. Includes articles, practice tests, software reviews, book reviews, and forums.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.certgear.com/products/vendor/java.htm"&gt;CertGear Systems - Java&lt;/a&gt; - http://www.certgear.com/products/vendor/java.htm Java certification resources, including practice tests (SCJP SCWCD SCBCD ), free quizzes, and study aids.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.examsguide.com/"&gt;Exams guide&lt;/a&gt; - http://www.examsguide.com Java certification resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://java.boot.by/scjp-tiger/"&gt;SCJP Tiger Study Guide&lt;/a&gt; - http://java.boot.by/scjp-tiger/ Study Guide for exam CX-310-055 (Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0).&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/gnashes30/java/mock.htm"&gt;VoodooExam&lt;/a&gt; - http://www.geocities.com/gnashes30/java/mock.htm SCJP mock exam engine with facility to add new question/answers. Needs jdk1.2.1 or higher [download].&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.inesystems.com/"&gt;Inesystem's Java Certification&lt;/a&gt; - http://www.inesystems.com Provides exam simulators and online training for Sun Java Certification exams.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://prasks.webahn.com/architect/scja.html"&gt;Prasks Resources&lt;/a&gt; - http://prasks.webahn.com/architect/scja.html Sun Certified Java Architect resources and experiences.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javadeveloper.co.in/"&gt;Java Certification Resources&lt;/a&gt; - http://www.javadeveloper.co.in Includes tutorials, mock exams, study notes and exam simulators for SCJP and SCWCD exams.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.tipsmart.com/"&gt;Tipsmart.com&lt;/a&gt; - http://www.tipsmart.com/ Contains interactive quizzes, pitfalls, FAQs by programmers, list of integrated development tools.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.valoxo.ch/jr/mocks/mock01a.html"&gt;Mock Exam&lt;/a&gt; - http://www.valoxo.ch/jr/mocks/mock01a.html Javascript based SCJP Mock Exam.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://home-1.tiscali.nl/~bmc88/java/javacert/"&gt;Java Certification Exam Questions&lt;/a&gt; - http://home-1.tiscali.nl/~bmc88/java/javacert/ SCJP mock tests, exam notes and other resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/rraje_2000/MockExam.html"&gt;SCJP2 MockExam&lt;/a&gt; - http://www.geocities.com/rraje_2000/MockExam.html 60 questions mock test [Download].&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/r_palwai/scjp.htm"&gt;Radhika Palwai's Web Development Resources&lt;/a&gt; - http://www.geocities.com/r_palwai/scjp.htm Contains links to SCJP resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.michael-thomas.com/"&gt;Free Java Certification Training&lt;/a&gt; - http://www.michael-thomas.com/ Contains mock tests, source code, resources for Sun Certifications, resources on Web-development and UML.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://dreamjava.blogspot.com/"&gt;Everything you want to know about SCJP&lt;/a&gt; - http://dreamjava.blogspot.com A Blog to help SCJP aspirants with links and daily question.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.jai.ch/"&gt;Learn + play Java&lt;/a&gt; - http://www.jai.ch/ Interactive, downloadable course for SCJP with built-in Java source interpreter. Work and experiment with class libraries using the tests and JLS Summary.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.certlobby.com/sun-java-certification.html"&gt;Sun Java Certification Resource Center&lt;/a&gt; - http://www.certlobby.com/sun-java-certification.html Contains concise details on various Sun certification exams and links to resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/developergrp/"&gt;Dallas SCJD Study Group&lt;/a&gt; - http://www.geocities.com/developergrp/ Developer exam resources including FAQs, guidelines, presentations, free books and discussion forum.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javaprogrammingworld.com/"&gt;Sun Java Certification SCJP, Java Tutorials and ebooks&lt;/a&gt; - http://www.javaprogrammingworld.com The contents of this page are intended for SCJP 1.2 exam (310-025) and resources specific to SCJP 1.4 exam (310-035).&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javacertificate.net/"&gt;Java Mock Exams, Practice Questions, Tutorails, Articles&lt;/a&gt; - http://www.javacertificate.net Contains practice questions and mock exams for various Sun and IBM certifications.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javaquestion.tripod.com/"&gt;JavaQuestion Bank&lt;/a&gt; - http://javaquestion.tripod.com/ Includes general and certification questions and other java resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.xyzws.com/"&gt;SUN Certification Study Materials&lt;/a&gt; - http://www.xyzws.com Provides study guides &amp; mock exams (needs registration) for SCJP 5.0 (CX-310-055) and SCDJWS (CX-311-220) tests.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.javaqueries.com/"&gt;JavaQueries&lt;/a&gt; - http://www.javaqueries.com/ SCEA Mock Exam, Solutions for JavaQueries.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.softlearn-systems.com/"&gt;SoftLearn Systems&lt;/a&gt; - http://www.softlearn-systems.com/ Provides simulators for SCBCD and SCJD exams. [Commercial]&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/rameshchhabra2002/Java/certification.htm"&gt;Universal teacher&lt;/a&gt; - http://www.geocities.com/rameshchhabra2002/Java/certification.htm SCJP exam simulator containing 600 questions [Download].&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.examsguide.com/scjp/freesimulator.html"&gt;SCJP Simulator&lt;/a&gt; - http://www.examsguide.com/scjp/freesimulator.html Offers an exam simulator with provision to add more questions.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://home.worldonline.dk/qjava/"&gt;Quick Java&lt;/a&gt; - http://home.worldonline.dk/qjava/ Contains a Java lookup reference and test-simulator based on a book.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://rohitgeorge.netfirms.com/scjp.html"&gt;Java Certification Guide&lt;/a&gt; - http://rohitgeorge.netfirms.com/scjp.html Contains tutorial on SCJP. Also contains a downloadable PDF version.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www-106.ibm.com/developerworks/java/library/j-scjp/"&gt;SCJP 1.4 certification primer&lt;/a&gt; - http://www-106.ibm.com/developerworks/java/library/j-scjp/ Outlines the new programmer certification exam with suggestions for preparation, sample questions and links to resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.angelfire.com/or/abhilash/"&gt;Abhilash's java quiz site&lt;/a&gt; - http://www.angelfire.com/or/abhilash/ Comprises of set of nine practice quizzes for SCJP exam with answers.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://otn.oracle.com/training/certification/jdeveloper_ocpds.html"&gt;Oracle Certified Java Developer&lt;/a&gt; - http://otn.oracle.com/training/certification/jdeveloper_ocpds.html Starting point for Oracle Certified Java Developer OCP program.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.korayguclu.de/"&gt;Home Page of Koray Guclu&lt;/a&gt; - http://www.korayguclu.de/ Contains excerpts from an ongoing SCJP book, exam information, notes and links to Mock exams/resources. Also publications, resume, photography, banner art.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.mycgiserver.com/~go4java/"&gt;go4java- Java Certification Site&lt;/a&gt; - http://www.mycgiserver.com/~go4java/ Includes SCJP experiences, FAQs, mock exams, tutorials and links to other resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/technofundo/tech/scjp/scjp.html"&gt;Java Programmer Certification&lt;/a&gt; - http://www.geocities.com/technofundo/tech/scjp/scjp.html SCJP Revision notes, links and other resources.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.webring.com/hub?ring=javacert"&gt;Java Certification Webring&lt;/a&gt; - http://www.webring.com/hub?ring=javacert Web-ring of sites involved with certification.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://home.worldonline.nl/~bmc88/java/javacert/revision.html"&gt;Sun Certified Programmer Examination Revision Book&lt;/a&gt; - http://home.worldonline.nl/~bmc88/java/javacert/revision.html SCJP Tutorial based on Sun's Objectives.&lt;br /&gt; &lt;a href="http://www.google.com/intl/en/dirhelp.html#pagerank"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://jamal.pisem.net/scjpnotes.htm"&gt;j-think&lt;/a&gt; &lt;br /&gt;&lt;a href="http://jamal.pisem.net/scjpnotes.htm"&gt; Contains SCJP notes.&lt;br /&gt; &lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.geocities.com/valoxo/scjp2/scjp2v1final.zip"&gt;Concentrated Guide to SCJP2&lt;/a&gt; - &lt;a href="http://www.geocities.com/valoxo/scjp2/scjp2v1final.zip"&gt; A zip archive consisting of SCJP Notes (PDF) and Questions and Answers (Word document) compiled by Ashraf Fouad Ayoub and Ashraf Samir Helmy.&lt;br /&gt; &lt;/a&gt;&lt;br /&gt;&lt;a href="http://blog.markwshead.com/archives/2005/01/02/taking-the-java-programmer-certification-exam.html"&gt;Passing the Java Programmer Certification Exam&lt;/a&gt; - &lt;a href="http://blog.markwshead.com/archives/2005/01/02/taking-the-java-programmer-certification-exam.html"&gt; Article discusses how to prepare for the Java Programmer certification. Includes suggestions on how to study for the exam.&lt;br /&gt; &lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.examnotes.net/forum71.html"&gt;Java certification forum&lt;/a&gt; - &lt;a href="http://www.examnotes.net/forum71.html"&gt; A discussion forum dedicated to Java certification exams.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6615883157507452442-4590813262074983771?l=nananthkrishna.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nananthkrishna.blogspot.com/feeds/4590813262074983771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6615883157507452442&amp;postID=4590813262074983771' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4590813262074983771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6615883157507452442/posts/default/4590813262074983771'/><link rel='alternate' type='text/html' href='http://nananthkrishna.blogspot.com/2007/07/certification-links.html' title=''/><author><name>ANANTH KRISHNA</name><uri>http://www.blogger.com/profile/14083069456447228169</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
