<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Techtracer &#187; Java EE</title>
	<atom:link href="http://techtracer.com/category/javaee/feed/" rel="self" type="application/rss+xml" />
	<link>http://techtracer.com</link>
	<description>Tracing the course of Web Technology</description>
	<lastBuildDate>Tue, 06 Jan 2009 12:14:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://techtracer.com</link>
  <url>http://techtracer.com/wp-includes/images/favicon.png</url>
  <title>Techtracer</title>
</image>
		<item>
		<title>The Great Hibernate Tutorial &#8211; a great jump start for beginners</title>
		<link>http://techtracer.com/2008/12/30/the-great-hibernate-tutorial-a-great-jump-start-for-beginners/</link>
		<comments>http://techtracer.com/2008/12/30/the-great-hibernate-tutorial-a-great-jump-start-for-beginners/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 05:42:17 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner tutorial for hibernate]]></category>
		<category><![CDATA[Hibernate Tutorial]]></category>
		<category><![CDATA[steps for hibernate setup]]></category>

		<guid isPermaLink="false">http://techtracer.com/?p=278</guid>
		<description><![CDATA[Hibernate has become the de-facto ORM (Object Relational Mapping) framework for most of the organizations today. It provides a very simple framework to overcome the cumbersome techniques involved with core JDBC implementations. Whenever there is a project based on database intrinsic activities it is advisable to use Hibernate than do JDBC coding. It saves a [...]]]></description>
			<content:encoded><![CDATA[<p>Hibernate has become the de-facto <strong>ORM</strong> (<a href="http://en.wikipedia.org/wiki/Object-relational_mapping" target="_blank">Object Relational Mapping</a>) framework for most of the organizations today. It provides a very simple framework to overcome the cumbersome techniques involved with core <strong>JDBC</strong> implementations. Whenever there is a project based on database intrinsic activities it is <strong>advisable</strong> to use Hibernate than do JDBC coding. It saves a huge amount of time revolving around unnecessary chores. </p>
<p>Having said that, the major question which strikes anyone who does majorly JDBC is that how does a Hibernate DAO layer look like. Without looking at a practical implementation one cannot be easily convinced to work on it. This is the only compelling reason why I intended to write <strong>The</strong> <strong>Great Hibernate Tutorial</strong>.</p>
<p>This tutorial is aimed at those developers who want to get a<strong> </strong>quick breifing on <strong>how to implement a DAO layer using Hibernate</strong>. This tutorial does not cover the basics of ORM nor a detailed explanation of Hibernate configurations or api. It follows on the same route as the <a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/" target="_self">Great Ant tutorial</a> which many readers liked.</p>
<p><strong>5 Steps to Designing a DAO in Hibernate:</strong></p>
<ol>
<li> Identify the tables which are required as entities in your project</li>
<li>Create the Hibernate Configuration file</li>
<li>Create the Hibernate entity mapping files (hbm) and entity classes</li>
<li>Make the DAO layer with the required functions</li>
<li>Test the DAO classes</li>
</ol>
<p><strong>Required Softwares</strong></p>
<p>The versions of the various open source software&#8217;s required for the implementation are</p>
<ul>
<li><a href="http://dev.mysql.com/downloads/mysql/5.1.html#win32" target=_blank>MySQL 5.0.5 for Windows</a></li>
<li><a href="http://dev.mysql.com/downloads/connector/j/5.0.html" target=_blank>MySQL ConnectorJ</a></li>
<li><a href="http://www.hibernate.org/6.html#A2" target=_blank>Hibernate Core 3.0</a></li>
<li><a href="http://java.sun.com/javase/downloads/index.jsp" target=_blank>JDK 1.5 or above</a></li>
<li><a href="http://www.eclipse.org/downloads/" target=_blank>Eclipse 3.3 or above</a></li>
</ul>
<p>So lets get going with<strong> the Great Hibernate Tutorial</strong>. The steps will explain you the specific details from the code while the actual code is present in the format of links at the <a href="#resources">bottom of this tutorial</a>. You can open the links in different tabs of your browser and then start reading the tutorial for getting a better understanding.</p>
<p><strong>Step 1. Identify the tables which are required as entities in your project</strong></p>
<p>For the tutorial I am designing a basic<strong> Attendance System</strong> for a company which currently has only two tables <strong>Employee</strong> and <strong>Dept</strong>. If your MySQL is not setup at the moment you may visit the tutorial on <a href="http://techtracer.com/2008/06/09/3-easy-steps-to-install-mysql-on-windows-xp/" target="_self">how to setup Mysql in windows XP</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`employee`</span> <span style="color: #FF00FF;">&#40;</span>                                                                                       
            <span style="color: #008000;">`psno`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">'0'</span><span style="color: #000033;">,</span>                                                                          
            <span style="color: #008000;">`name`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>                                                                              
            <span style="color: #008000;">`pass`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>                                                                              
            <span style="color: #008000;">`proj<span style="color: #008080; font-weight: bold;">_</span>cd`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>                                                                               
            <span style="color: #008000;">`dept<span style="color: #008080; font-weight: bold;">_</span>name`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>                                                                             
            <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #990099; font-weight: bold;">USING</span> <span style="color: #990099; font-weight: bold;">BTREE</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`psno`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>                                                                            
            <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`FK<span style="color: #008080; font-weight: bold;">_</span>employee<span style="color: #008080; font-weight: bold;">_</span>newfk`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`proj<span style="color: #008080; font-weight: bold;">_</span>cd`</span><span style="color: #000033;">,</span><span style="color: #008000;">`dept<span style="color: #008080; font-weight: bold;">_</span>name`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>                                                              
            <span style="color: #990099; font-weight: bold;">CONSTRAINT</span> <span style="color: #008000;">`employee<span style="color: #008080; font-weight: bold;">_</span>ibfk<span style="color: #008080; font-weight: bold;">_</span>1`</span> <span style="color: #990099; font-weight: bold;">FOREIGN KEY</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`proj<span style="color: #008080; font-weight: bold;">_</span>cd`</span><span style="color: #000033;">,</span> <span style="color: #008000;">`dept<span style="color: #008080; font-weight: bold;">_</span>name`</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">REFERENCES</span> <span style="color: #008000;">`dept`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`PROJ<span style="color: #008080; font-weight: bold;">_</span>CD`</span><span style="color: #000033;">,</span> <span style="color: #008000;">`DEPT<span style="color: #008080; font-weight: bold;">_</span>NAME`</span><span style="color: #FF00FF;">&#41;</span>  
          <span style="color: #FF00FF;">&#41;</span> 
&nbsp;
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`dept`</span> <span style="color: #FF00FF;">&#40;</span>                   
          <span style="color: #008000;">`PROJ<span style="color: #008080; font-weight: bold;">_</span>CD`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>       
          <span style="color: #008000;">`DEPT<span style="color: #008080; font-weight: bold;">_</span>NAME`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>     
          <span style="color: #008000;">`START<span style="color: #008080; font-weight: bold;">_</span>DATE`</span> <span style="color: #999900; font-weight: bold;">date</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>       
          <span style="color: #008000;">`TYPE`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>      
          <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`PROJ<span style="color: #008080; font-weight: bold;">_</span>CD`</span><span style="color: #000033;">,</span><span style="color: #008000;">`DEPT<span style="color: #008080; font-weight: bold;">_</span>NAME`</span><span style="color: #FF00FF;">&#41;</span>  
        <span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>The Employee and Dept have a one to many relationship. From the DDL it is evident that Dept table has composite keys. Usually <a href="http://codebetter.com/blogs/jeremy.miller/archive/2007/02/01/Composite-keys-are-evil.aspx" target="_blank">composite keys are considered evil</a> , but I am using it just for the sake of presenting a use case of <strong>configuring composite keys in hibernate</strong>.</p>
<p><strong>Step 2. Create the Hibernate Configuration file </strong></p>
<p>The Hibernate configuration file is where you provide all the connection level details. It is very straightforward configuration and appears similar to your JDBC connection statements. But unlike JDBC, you can specify many more things here like <strong>caching, dialects, debug queries</strong>. One important aspect of this configuration file is providing path of <strong>hbm</strong> files. Check the following two line of XML.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;com/abc/entities/Employee.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>     
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;com/abc/entities/Dept.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>These lines are important. They specify the paths to your entity mapping files. Entity mapping files are those <strong>XML files</strong> which tell hibernate as to how the entity classes relate to the tables. It defines how the data should flow from class properties to the table columns. But you have to be careful in mentioning the <strong>paths</strong> to the mapping files. It is not required that the files be kept in the packages as I have done but it is considered a convention.</p>
<p><strong>Step 3. Create the Hibernate entity mapping files (hbm) and entity classes</strong></p>
<p>In this step we would be actually defining the <strong>mapping</strong>. I have kept all the entities in the package <strong>com.abc.entities</strong> along with the mapping files. The first element is obvious <em>&lt;hibernate-mapping&gt;</em>. Within this element you would most of the times define 3 elements: Class, ID and Property.</p>
<p><strong>Class</strong> &#8211; the class for which mapping to the table is being defined</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.abc.entities.Employee&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;employee&quot;</span> <span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>One extra attribute of the element you would notice is lazy=&#8221;false&#8221;. This is the lazy loading technique of ORM the details of which are beyond the scope of this tutorial. You may even not mention it.</p>
<p><strong>ID &#8211; Primary key</strong> is an absolute must in hibernate mapped tables. Primary Keys are mapped to ID as follows</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;psno&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;psno&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;assigned&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Generator </strong>means how the primary key is populated. If it was <strong>auto generated</strong> in the table then the value should have been &#8220;<strong>auto</strong>&#8220;. The value &#8220;<strong>assigned</strong>&#8221; means we will set it in the application itself. In case of Dept, since composite key exists we should define it as</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite-id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deptPK&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.abc.entities.DeptPK&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;projCode&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;PROJ_CD&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deptName&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;DEPT_NAME&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Property</strong> &#8211; These are columns which would be made as properties having getters and setters in the class definition</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>this would map name property of Employee class to the name column of employee table.</p>
<p><span style="text-decoration: underline;"><strong>Associations in Hibernate</strong></span></p>
<p>The above 3 are majorly used. Apart from that you can also mention <strong>cardinality mapping</strong> if required as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;many-to-one</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dept&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.abc.entities.Dept&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;proj_cd&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dept_name&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/many-to-one<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Since I have a <strong>composite key</strong> in Dept table I have mentioned two columns in the above mapping. This mapping can be read as &#8220;<em>MANY Employees are related TO ONE Dept with help of COLUMNS proj_cd and dept_name</em>&#8220;. These mappings are called as <strong>Associations </strong>in hibernate.</p>
<p>In the Dept mapping file since one dept can return <strong>multiple</strong> Employees, they would be returned in the form of a<strong> set</strong>. Hence we would have to map the set of Employee as:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;employees&quot;</span> <span style="color: #000066;">inverse</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;proj_cd&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dept_name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;one-to-many</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.abc.entities.Employee&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The<strong> inverse=&#8221;true&#8221;</strong> says that the association is <strong>bidirectional</strong> which is another important concept in hibernate. In a bidirectional relationship you can reach an associated element from within one element and same applies the other way too. On the contrary you may even have <strong>unidirectional</strong> relationship in which you don&#8217;t specify mapping in the other classes.</p>
<p><span style="text-decoration: underline;"><strong>Defining Entity classes</strong></span></p>
<p>This is straight forward. Entity classes are simple <a href="http://en.wikipedia.org/wiki/JavaBeans" target="_blank">Java Beans</a>. You can view the class definition in the links provided at the bottom of this post. A <strong>no argument public constructor </strong>is a must in case you define a custom one.</p>
<p>One special case here would be for composite keys. Composite keys are defined in a <strong>separate class</strong>. After this, In the class where composite keys are required you would have to make a property of the composite-class-type.</p>
<p><strong>Step 4. Make the DAO layer with the required functions</strong></p>
<p>Finally we are the moment of salvation. The thing which we were waiting eagerly for implementing. The DAO layer. It is always a good practice to make a separate DAO class for holding utility functions. Hibernate requires that you always open a <strong>session</strong> before accessing the database and making <strong>transactions </strong>when you update the database. This requires repeatable lines of code.</p>
<p>So in order to avoid repeating ourselves its better to keep these lines of code in a DAO class as shown in the links below. Check for <em><strong>com.abc.dao.DAO.java</strong></em>. You may use the class as it is since it is a routine code. For coding your own classes to make use of the utility functions in the DAO extend your class with this <em><strong>DAO.</strong></em></p>
<p>Lets have a look at <em><strong>AdminDAO</strong></em>. Since I belive in interface based implementations I have provided <em><strong>AdminDAO</strong></em> as an interface and <em><strong>AdminDAOHibernateImpl</strong></em> as its implementation which extends <em><strong>DAO</strong></em>. The code is kept simple for understanding purposes. The things worth pondering are:</p>
<p>In functions which do an update on the tables you have to carry the following steps:</p>
<ol>
<li>begin();</li>
<li>getSession()&#8230;.; // save or update</li>
<li>commit();</li>
<li>rollback();  //in case of HibernateException and throw any custom business exception if required</li>
</ol>
<p>For fetching data you don&#8217;t need transactions so you don&#8217;t need to do the above steps. In this case you can just execute a query via the <em>getSession() </em>as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">Query</span> q = getSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Employee e inner join fetch e.dept where e.psno = :psno&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
q.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;psno&quot;</span>, psno.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Employee emp = <span style="color: #009900;">&#40;</span>Employee<span style="color: #009900;">&#41;</span> q.<span style="color: #006633;">uniqueResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span style="text-decoration: underline;"><strong>Hibernate Query Language</strong></span></p>
<p>The above query syntax is called <strong>HQL (Hibernate Query Language)</strong>. It is syntactically very similar to JDBC with the difference that HQL queries are based on objects and not on tables so the names are <strong>case sensitive</strong> and <strong>aliases</strong> to objects are a must.</p>
<p>In HQL, you can either fetch a single result when you know that there would be exactly one row fetched. When you know that mutiple records might be returned then you can fetch the list as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">Query</span> q = getSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Employee&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
List<span style="color: #339933;">&lt;</span>Employee<span style="color: #339933;">&gt;</span> list = q.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> list<span style="color: #339933;">;</span></pre></div></div>

<p><span style="text-decoration: underline;"><strong>Paging in Hibernate</strong></span></p>
<p>You can obtain paging in Hibernate very easily without any additional efforts by applying a max results criteria</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">q.<span style="color: #006633;">setFirstResult</span><span style="color: #009900;">&#40;</span>firstResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
q.<span style="color: #006633;">setMaxResults</span><span style="color: #009900;">&#40;</span>maxResults<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Doesn&#8217;t it feel really good. JDBC users might feel jealous at this time1</p>
<p><strong>Step 5. Test the DAO classes</strong></p>
<p>Now, to our final strike. The testing can be done with POJO&#8217;s. For the tutorial I had created a service layer since I usally access teh DAO layer through the service layer. So the testing was done on the service layer instead of the DAO as this application was small. You can however test out directly the DAO functions.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">static</span> <span style="color: #006600; font-weight: bold;">void</span> listTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		List<span style="color: #339933;">&lt;</span>Employee<span style="color: #339933;">&gt;</span> employees = adminService.<span style="color: #006633;">getAllEmployees</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000;  font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Employee emp: employees<span style="color: #009900;">&#41;</span>
			<span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>emp.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>AppException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Wasn&#8217;t that a breeze? I hope that it was. Once you gain a thorough knowledge of <strong>ORM concepts </strong>then you would appreciate working with <strong>Hibernate</strong> even more. For further knowledge, I would recommend you to go through the <a href="http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch" target="_blank">impedence mismatch theory</a> to know the fundamental flaws surrounding JDBC. Working with Hibernate would then be real fun.</p>
<p>Enjoy folks!<br />
<a name="resources"></a><br />
<u><strong>Resources for the tutorial</strong></u></p>
<p>The below files are required for running the above tutorial. Copy these to your eclipse project and add the required libraries of hibernate and mysql before running the project.</p>
<p><em>Configuration</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/hibernatecfg.xml' target=_blank>hibernate.cfg.xml</a></p>
<p><em>Package: com.abc.entities</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/employeejava.txt' target=_blank>com.abc.entities.Employee.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/employeehbm.xml' target=_blank>Employee.hbm.xml</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/deptjava.txt' target=_blank>com.abc.entities.Dept.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/deptpkjava.txt' target=_blank>com.abc.entities.DeptPK.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/depthbm.xml' target=_blank>Dept.hbm.xml</a></p>
<p><em>Package: com.abc.dao</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/daojava.txt' target=_blank>com.abc.dao.DAO.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/admindaojava.txt' target=_blank>com.abc.dao.AdminDAO.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/admindaohibernateimpljava.txt' target=_blank>com.abc.dao.AdminDAOHibernateImpl.java</a></p>
<p><em>Package: com.abc.service</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/adminservicejava.txt' target=_blank>com.abc.service.AdminService.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/adminserviceimpljava.txt' target=_blank>com.abc.service.AdminServiceImpl.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/deptservicejava.txt' target=_blank>com.abc.service.DeptService.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/deptserviceimpljava.txt' target=_blank>com.abc.service.DeptServiceImpl.java</a></p>
<p><em>Package: com.abc.exceptions</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/appexceptionjava.txt' target=_blank>com.abc.exceptions.AppException.java</a></p>
<p><em>Package: com.abc.tests</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/depttestjava.txt' target=_blank>com.abc.tests.DeptTest.java</a></p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/" rel="bookmark" title="Permanent Link: The Technique of Virtual Deployment in Tomcat">The Technique of Virtual Deployment in Tomcat</a></li><li><a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/" rel="bookmark" title="Permanent Link: The Great Ant Tutorial &#8211; a great jump start">The Great Ant Tutorial &#8211; a great jump start</a></li><li><a href="http://techtracer.com/2008/01/09/impressive-google-chart-generator-scripts/" rel="bookmark" title="Permanent Link: Impressive Google Chart Generator Scripts">Impressive Google Chart Generator Scripts</a></li><li><a href="http://techtracer.com/2007/03/09/hello-world/" rel="bookmark" title="Permanent Link: Tracing the route of technology">Tracing the route of technology</a></li><li><a href="http://techtracer.com/2007/10/06/mozillas-new-killer-app-the-webrunner/" rel="bookmark" title="Permanent Link: Mozilla&#8217;s New Killer App &#8211; The WebRunner">Mozilla&#8217;s New Killer App &#8211; The WebRunner</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/12/30/the-great-hibernate-tutorial-a-great-jump-start-for-beginners/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>BEA Dev2Dev TechDays &#8211; An Experience</title>
		<link>http://techtracer.com/2008/05/11/bea-dev2dev-techdays-an-experience/</link>
		<comments>http://techtracer.com/2008/05/11/bea-dev2dev-techdays-an-experience/#comments</comments>
		<pubDate>Sun, 11 May 2008 18:57:51 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/05/11/bea-dev2dev-techdays-an-experience/</guid>
		<description><![CDATA[BEA had invited people across India for attending their TechDays sessions of which Adobe was the event partner. I had  registered for it almost a month ago. It was held on May 9th Friday at The Leela, a  five star hotel in Andheri, Mumbai. The timings for the session were from 9:00 am [...]]]></description>
			<content:encoded><![CDATA[<p><strong>BEA</strong> had invited people across India for attending their <a href="http://www.shobiziems.com/BEA_Dev2Dev_days_2008/mumbai.html" target="_blank">TechDays sessions</a> of which <strong>Adobe</strong> was the event partner. I had  registered for it almost a month ago. It was held on <strong>May 9th</strong> Friday at <a href="http://www.theleela.com/hotel-mumbai.html" target="_blank">The Leela</a>, a  five star hotel in Andheri, Mumbai. The timings for the session were from <strong>9:00 am</strong> till <strong>12:00 pm </strong>and no registration nor event fees were taken. Here is my experience about the entire event.</p>
<p><strong>The Sessions</strong></p>
<p><img src="http://lh4.ggpht.com/nitinclicks/SCQhOxm8wpI/AAAAAAAAAzU/oxcSob4G_vo/s288/DSC04315.JPG" style="float: left; margin-right: 15px; margin-bottom: 5px" height="216" width="288" /></p>
<p>The session was primarily held for the developers community and less for the  corporate. This provided a relief as there weren&#8217;t much marketing gimmicks being  played and the speakers were purely techie guys which proved to be an onus. BEA  has upgraded their <strong>Weblogic Server</strong> to version <strong>10.2</strong> and their <strong>Workshop</strong> too. I had  worked on the BEA workshop studio and Aqualogic platform for ESB earlier. So my  main interests lied in what new features these upgraded products had in their  offerings. After having attending this session I am now all the more excited to  work in the BEA platform.</p>
<p>Although many people were awestruck with the features  and some felt jealous for continuing to work on the older versions at their  workplace, one thing was going through the minds of many including mine. The  question was as to what was the road map for these BEA products since now the <a href="http://techtracer.com/2008/01/23/effects-of-oracle-bea-acquisition/">acquisition  by Oracle</a> has got completed. There was a slight wave of <strong>concern</strong> over this  <strong>merger</strong> on the current developers as well as for those who wanted to adopt to the  BEA environment in future. Would Oracle continue to<strong> support</strong> active upgradation  to these wonderful products or take away the key features from them to promote  its own products? The concerns were raised higher during the session when the  BEA guys told us that were not too sure of the road map either. We will have to  keep fingers crossed for that.</p>
<p>There were <strong>3 speakers</strong> for the entire session out of which 2 were from BEA,  now christened <strong>Oracle BEA</strong> and one evangelist from <strong>Adobe</strong>. You may wonder where  does Adobe form a part of the BEA endeavor? I was curious too. The curiosity  was cleared by one of the BEA speakers on mentioning that Adobe had integrated  its Flex platform for the BEA environment. Piggybacking for publicity you may  call. But it is actually awesome.</p>
<p><strong>BEA Java2SOA Revolution</strong></p>
<p><img src="http://lh6.ggpht.com/nitinclicks/SCQh8Rm8w3I/AAAAAAAAA1M/wd7MdgDFNJU/s288/DSC04336.JPG" style="float: right; margin-left: 15px; margin-bottom: 5px" height="216" width="288" /></p>
<p>The session started with the first speaker <strong>Sandeep Sonkusale</strong> who is a  certified SOA Solution Architect for BEA speaking on the aspects of why an  organization has to choose to the SOA infrastructure and the underlying benefits  that SOA would provide. The briefing was accompanied with several high profile  diagrams of how the world would be revolutionized if SOA would be adopted. I  could see many people yawning to glory for this completely hypothetical preachy  stuff. All were waiting for the meaty part i.e how to go about doing it. After  waiting for almost 45 minutes for the briefing to get over, we felt a wave of  relief when the second speaker took over with his laptop and workshop running on  the presentation screen.</p>
<p>The second speaker was a young and smart looking<strong> Anil Sharma</strong> from the BEA  product development team. His ascent was really professional. Right from the  start to the end of a 2 hour long demo he had his cool even though people  bombarded him with several technical queries. The demo given was on the entire  new version of the <strong>BEA Workshop Studio</strong>. It is now entirely eclipse based and has  all the earlier separate workshops integrated into one. This means that having  workshop installed on your system you can build all the components of J2EE  architecture, create <strong>web services</strong>, build beehive<strong> controls</strong> for exposing the J2EE  components as <strong>services</strong>, convert these controls to web services, perform <strong>BPM  process flows</strong> and later expose them too as services, connect all controls or  services to <strong>Aqualogic Service Bus</strong>, convert the services to presentation <strong>portals  </strong>and much much more. Phew! This entire demo was a roller coaster for me but it  was real fun.</p>
<p>The key points which I found to be useful were the ones which the speaker was  emphasizing on and on. It is<strong> not necessary</strong> that you need to create web services  for making your architecture SOA enabled. You can have services like EJB  services, custom control services as well web services to make an SOA. Controls  are used to expose EJB&#8217;s or POJO&#8217;s as services and these are not Weblogic  specific. In fact they are <a href="http://beehive.apache.org/" target="_blank">Apache Beehive</a> controls which are a part of <a href="http://jcp.org/en/jsr/detail?id=175" target="_blank">JSR 175</a>, hence  vendor lock-in can be avoided. I am not too sure if any other J2EE provider has  beehive controls implementation apart from Weblogic 10.2. The interfaces and  implementations of web services are done using the <a href="http://jcp.org/en/jsr/detail?id=181" target="_blank">JSR-181</a>  constructs.</p>
<p><img src="http://techtracer.com/wp-content/uploads/2008/05/oracle_bea_logo.jpg" alt="Oracle_BEA_Logo" /> <img src="http://techtracer.com/wp-content/uploads/2008/05/dev2dev_techdays.gif" alt="Dev2Dev_TechDays_Logo" /></p>
<p>I got to understand the use of <a href="http://en.wikipedia.org/wiki/Business_Process_Management" target="_blank">BPM</a> through this session. Before this, I was really hazy as to  which use cases BPM really favors. Anil, through his demo explained this in a  peculiar scenario. When there is a need to have an entire stateful process as a  service it can be implemented as a BPM workflow through the Workshop itself.  This can be further exposed as a service. Services can be further integrated  into the <a href="http://e-docs.bea.com/alsb/docs20/index.html" target="_blank">Aqualogic Service Bus</a> (ALSB) for implementing a transactional  service workflow. It is important to note that the services integrated into the  service bus must support transaction to have transactional behavior.</p>
<p>The major surprise to me was the merger of <a href="http://dev2dev.bea.com/pub/a/2005/06/whats_new_dsp.html" target="_blank">DSP</a> into the Workshop. In between the workflow wherever you  need a transformation of data you can easily use Data Services transformation  either through <strong>XQuery</strong> or <strong>Java</strong> right within the workflow. This was something  amazing.</p>
<p>Finally shown, were the presentation services based on <strong>Weblogic Portal</strong>  platform. In order to create presentation services BEA workshop comes built in  with <a href="http://beehive.apache.org/docs/1.0/netui/overview.html" target="_blank">NetUI</a> which is the <strong>pageflow</strong> modeller for the <strong>Struts</strong> framework.  Using NetUI you can create Struts JSP views directly from exposed services which  further can be converted to <a href="http://docs.oasis-open.org/wsrp/v2/wsrp-2.0-spec-os-01.html" target="_blank">WSRP portlets</a> and integrated into the application portal. The  most surprising aspect of the WSRP portlets is that you can access the portlet  remotely too. This means that your view would be actually rendered from a remote server!</p>
<p><strong>Adobe &#8211; G</strong><strong>etting More and More Flexy</strong></p>
<p>From 9:30 am to 12:15 pm the BEA guys took the center stage. The Adobe guy  was nowhere to be seen. Right at 12:15 pm he popped from somewhere with his  laptop and took charge. His session may have been just a 45 minute one but the  impact was majestic. He transformed the crowd of almost 200 odd people to the  edge of their seats and eyes wide gaping to the screen with his magical Flex  demo. It was showtime for <a href="http://raghuonflex.wordpress.com/" target="_blank">Raghu Rao</a>, <strong>evangelist </strong>for the <strong>Flex platform</strong> for Adobe. His  charisma was attention capturing and the way he breezed through the Flex demo,  he left the geek&#8217;s including me, craving for more.</p>
<p><img src="http://lh6.ggpht.com/nitinclicks/SCQh7Rm8wzI/AAAAAAAAA0s/7pMk10oToMQ/s288/DSC04330.JPG" style="float: left; margin-right: 15px; margin-bottom: 5px" height="216" width="288" /></p>
<p>The presentation involved the showcase of Flex as a presentation level  service for the BEA platform. He presented how Flex can be used for accessing  the services exposed from the BEA environment into the presentation tier. This  included the use of the commercial <a href="http://www.adobe.com/products/livecycle/dataservices/" target="_blank">Adobe  product LCDS</a> which is an enterprise level Flex platform for services. If you  do not want to go the paid way, you can use <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS" target="_blank">BlazeDS</a> which is a open source freeware, but with limited  capabilities, suitable for small applications. Using these you can make callouts  to the hosted services using the <a href="http://en.wikipedia.org/wiki/Action_Message_Format" target="_blank">Action  Message Format (AMF)</a> for remote calls.</p>
<p>The major source attraction proved to be the Flex demo&#8217;s, which included the  Nokia Shop and a sample consumer application. The <a href="http://demo.quietlyscheming.com/ChartSampler/app.html" target="_blank">Flex  charts</a> components and 3rd party flex UI components such as <a href="http://dougmccune.com/blog/2007/11/19/flex-coverflow-performance-improvement-flex-carousel-component-and-vertical-coverflow/" target="_blank">coverflow component</a> and the <a href="http://www.rubenswieringa.com/blog/flex-book-component-beta" target="_blank">Flex Book component</a> snatched away everyone&#8217;s breath.</p>
<p><strong>Final Notes<br />
</strong></p>
<p>Such sessions really help in accessing the direction of where technology is  heading to. I am thankful to Anil and Raghu who personally cleared my confusions  over some aspects offline. I felt bad to keep Raghu away from his food since I  kept him bugging with my questions. He had to catch a flight to Bangalore a  little while later. If you would like to evaluate the all new <a href="http://edocs.bea.com/wlw/docs102/" target="_blank">BEA Weblogic 10.2  platform</a> head straight towards their <a href="http://dev2dev.bea.com/evalguide/" target="_blank">eval guide</a> for  getting started and also win a <strong>32 GB Ipod</strong> by taking this <a href="http://www.surveymonkey.com/s.aspx?sm=HnVokokDlCgyiuwuFNhARQ_3d_3d" target="_blank">survey</a>. <img src='http://techtracer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Check out the day&#8217;s captures on my <a href="http://picasaweb.google.com/nitinclicks/TheLeela" target="_blank">picassa  web album</a>.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/05/12/developers-dilemma-pride-or-prestige/" rel="bookmark" title="Permanent Link: Developers Dilemma &#8211; pride or prestige">Developers Dilemma &#8211; pride or prestige</a></li><li><a href="http://techtracer.com/2007/10/26/what-makes-facebook-win-over-orkut/" rel="bookmark" title="Permanent Link: What Makes Facebook Win Over Orkut?">What Makes Facebook Win Over Orkut?</a></li><li><a href="http://techtracer.com/2007/10/06/mozillas-new-killer-app-the-webrunner/" rel="bookmark" title="Permanent Link: Mozilla&#8217;s New Killer App &#8211; The WebRunner">Mozilla&#8217;s New Killer App &#8211; The WebRunner</a></li><li><a href="http://techtracer.com/2006/10/16/bea-aqualogic-data-services-platform-first-glimpse/" rel="bookmark" title="Permanent Link: BEA Aqualogic Data Services Platform &#8211; First Glimpse">BEA Aqualogic Data Services Platform &#8211; First Glimpse</a></li><li><a href="http://techtracer.com/2007/10/13/hp-snapfish-india-for-cost-effective-printing/" rel="bookmark" title="Permanent Link: HP Snapfish India, For Cost Effective Printing">HP Snapfish India, For Cost Effective Printing</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/05/11/bea-dev2dev-techdays-an-experience/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The Technique of Virtual Deployment in Tomcat</title>
		<link>http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/</link>
		<comments>http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 16:17:54 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/</guid>
		<description><![CDATA[The most common ways of deploying a web application to Tomcat are either straightaway copy the exploded war file structure to $CATALINA_HOME/webapps or to do the more cumbersome task of compiling the web application to a war file and then using the tomcat manager to upload it. Both ways are the most used ones. But [...]]]></description>
			<content:encoded><![CDATA[<p>The most common ways of deploying a web application to Tomcat are either straightaway copy the exploded <strong>war </strong>file structure to <strong>$CATALINA_HOME/webapps</strong> or to do the more cumbersome task of compiling the web application to a war file and then using the tomcat manager to upload it. Both ways are the most used ones. But did you know there are other ways to deploy a web application to Tomcat. If you consider production environments, then applications are deployed using the deployment commands, if at all Tomcat is used. They can be made more simpler using the <a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/">ant tasks</a>.</p>
<p>But I am not going to discuss the production environment over here. The topic under scrutiny is how would you deploy your web application virtually to Tomcat. For that we have to know what is virtual deployment and learn about its advantages.</p>
<p><strong>What is virtual deployment?</strong></p>
<p>Virtual deployment in simple terms means deploying a web application from a different physical location. In this case, you are not required to put the web application in its exploded war structure to the <strong>webapps </strong>directory. Most of the beginners, tend to develop their web applications directly in the webapps directory itself. This technique might prove the most simplest and the quickest but it is the<strong> most hazardous</strong>. This is because the moment you <strong>Undeploy</strong> the web application from Tomcat&#8217;s manager the web application gets<strong> erased</strong> off completely from the webapps directory.</p>
<p>I had tried the same, for the very first time since I had not much information, and it proved fatal. All my work had vanished in an instant. From that day onwards I stuck to using a technique of using <a href="http://techtracer.com/2007/03/31/development-and-deployment-structures-the-perfect-way-to-build-a-web-application/">development structures and deployment structures</a> and used with Ant. But I found this, too cumbersome, if I had to learn a framework or try out a small sample code. I was not willing to write an Ant build file each time I had to try a web application nor I wanted to develop the web application straightaway in the webapps directory which had earlier destroyed my work. IDE&#8217;s might be of great help but I don&#8217;t usually have them when needed. For example at a friend&#8217;s place.</p>
<p>Coming back to the topic which I have to discuss, I recently found a good workaround for the above problem. Although I believe it might be used quite commonly to deploy web applications I am writing this for people who are facing the same problem as mine. The solution lies in deploying the web application virtually.</p>
<p><strong>How to virtually deploy a web application in Tomcat?</strong></p>
<p>When you virtually deploy a web application you are just saying to Tomcat that you have developed a web application which is lying in some other location and that the server should run it from that location itself. This is done by using a configuring element called <strong>Context</strong>. In Tomcat lingo Context is nothing but the web application itself.</p>
<p>So here is the technique of virtual deployment done in Tomcat. I am using <strong>Tomcat 6</strong> for this example.</p>
<ul>
<li>Let&#8217;s assume that Tomcat is configured at the location <strong>C:/Tomcat6</strong></li>
<li>Place the Web application at some other location. For example <strong>D:/workspace/WebApp</strong></li>
<li>Start Tomcat. This is to test the hot deployment of our Context</li>
<li>Now go to the path C:/Tomcat6/<strong>conf/</strong></li>
<li>Check if you have the directory <strong>Catalina</strong> and a subdirectory <strong>localhost</strong> within it</li>
<li>If you don&#8217;t have them then you must make the directories <strong>Catalina/localhost</strong> within C:/Tomcat6/conf/</li>
<li>Make a Context file and name it with any name, <strong>myapp.xml</strong> and place it within localhost</li>
<li>You have to put a single element within the <strong>myapp.xml</strong> as follows<br />
<blockquote><p>&lt;Context<br />
docBase=&#8221;D:/workspace/WebApp&#8221;<br />
reloadable=&#8221;true&#8221;/&gt;</p></blockquote>
</li>
<li>The &#8220;<strong>reloadable</strong>&#8221; attribute is optional. The &#8220;<strong>docBase</strong>&#8221; attribute is required. It is used to specify the physical location of the web app.</li>
<li>That&#8217;s it. Now you can do any kind of tests with your web application and happily see the changes with just a browser refresh.</li>
<li>Try undeploying your web app now. The moment you undeploy, myapp.xml gets <strong>deleted</strong> from Catalina/localhost but your application will be intact. Isn&#8217;t that wonderful?</li>
<li>For redeploying you would just have to make myapp.xml once again.</li>
</ul>
<p>If you want to learn more about configuring Contexts and look at its different attributes then go through the <a href="http://tomcat.apache.org/tomcat-6.0-doc/config/context.html" target="_blank">tomcat reference</a>. But before that, you would want to know what are the advantages of this technique.</p>
<p><strong>Advantages of Virtual Deployment</strong></p>
<p>When a context is configured, Tomcat runs it from the location directly where the web application is placed and not by making a copy in its webapps directory. In this case if you try to Undeploy the web application, Tomcat simply removes the context file from its directory and does not touch the physical web application. This is most convenient and easy way to deploy a web application to Tomcat without the fear of losing your work.</p>
<p>The <strong>second </strong>advantage of virtual deployment is that you don&#8217;t have to change anything in the <strong>server.xml</strong>. Whenever any change is made in server.xml the server has to be restarted for the changes to be applied. In case of using contexts the server <strong>automatically</strong> deploys your application when it finds any context newly configured with it.</p>
<p>The <strong>third</strong> advantage is that contexts can be even used to make your web applications <strong>classes</strong> hot deployable too. It is done as above using the  &#8220;<strong>reloadable</strong>&#8221; attribute. Tomcat picks up any changes done even to the classes if &#8220;reloadable&#8221; is set to &#8220;<strong>true</strong>&#8220;. This can be very helpful and a time savior if you don&#8217;t want to waste time in restarting Tomcat again and again. It is however <strong>heavy </strong>on resources but might be useful in simple tests.</p>
<p>The <strong>fourth</strong> advantage is that you can dynamically change the<strong> name</strong> of your application itself. For example change the name of &#8220;myapp.xml&#8221; to &#8220;BankApp.xml&#8221;. Go to Tomcat Manager URL and refresh it. You will see the application name as &#8220;BankApp&#8221; which earlier was &#8220;myapp&#8221;. It doesn&#8217;t matter what the folder name is where the actual application lies. In our case it was &#8220;WebApp&#8221;.</p>
<p>The <strong>fifth</strong> advantage is something I found it to be <strong>the best</strong> of all. Your application would run even if it actually present on a <strong>remote machine</strong>. What you need to do is to just share the application from one machine, set the <strong>docBase</strong> path as the <strong>network URI</strong> and then access it. It would run like a locally hosted application.</p>
<p>The last but not the least advantage is to test a sample code on <strong>multiple </strong>tomcat&#8217;s. Let&#8217;s assume you want to test a feature of servlets to find whether it is backward compatible or not. So you can have a new Tomcat and an old Tomcat running on different ports. Put the context in both Tomcat&#8217;s and simultaneously test it out. You would have to refer to the Tomcat documentation for configuring Context in the older versions.</p>
<p>Now that you know how the technique of virtual deployment try it out on different servers like <strong>Glassfish</strong> or <strong>JBoss</strong> and let me know how you went about it. Cheers!</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/03/31/development-and-deployment-structures-the-perfect-way-to-build-a-web-application/" rel="bookmark" title="Permanent Link: Development and Deployment Structures &#8211; the perfect way to build a web application">Development and Deployment Structures &#8211; the perfect way to build a web application</a></li><li><a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/" rel="bookmark" title="Permanent Link: The Great Ant Tutorial &#8211; a great jump start">The Great Ant Tutorial &#8211; a great jump start</a></li><li><a href="http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/" rel="bookmark" title="Permanent Link: Setting Up SSL on Tomcat In 3 Easy Steps">Setting Up SSL on Tomcat In 3 Easy Steps</a></li><li><a href="http://techtracer.com/2007/04/07/annotations-in-pojo-a-boon-or-a-curse/" rel="bookmark" title="Permanent Link: Annotations in POJO &#8211; a boon or a curse?">Annotations in POJO &#8211; a boon or a curse?</a></li><li><a href="http://techtracer.com/2007/09/03/and-i-thought-i-knew-how-java-worked/" rel="bookmark" title="Permanent Link: And I thought I Knew How Java Worked!">And I thought I Knew How Java Worked!</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Designing Enterprise Applications &#8211; Approaches and Patterns</title>
		<link>http://techtracer.com/2008/03/30/designing-enterprise-applications-approaches-and-patterns/</link>
		<comments>http://techtracer.com/2008/03/30/designing-enterprise-applications-approaches-and-patterns/#comments</comments>
		<pubDate>Sun, 30 Mar 2008 16:07:34 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Concepts]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Java EE]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/03/30/designing-enterprise-applications-approaches-and-patterns/</guid>
		<description><![CDATA[JavaWorld has published a useful research paper which discusses how to discern which design patterns and frameworks would work best for your enterprise applications, written by Chris Richardson. As a developer it is very essential to know about the different strategies one would adopt in a particular business scenario. This paper helps you in making [...]]]></description>
			<content:encoded><![CDATA[<p><strong>JavaWorld</strong> has published a useful research paper which discusses how to discern <a href="http://www.javaworld.com/javaworld/jw-01-2006/jw-0130-pojo.html" target="_blank">which design patterns</a> and frameworks would work best for your enterprise applications, written by Chris Richardson<strong>.</strong> As a developer it is very essential to know about the different strategies one would adopt in a particular business scenario. This paper helps you in making important decisions about which <a href="http://techtracer.com/2007/06/10/design-patterns-building-blocks-for-your-application/">design patterns</a> would best suite a given set of requirements.</p>
<p>According to the research done by Chris for enterprise applications, here are some of the important points which the paper elaborates:</p>
<ol id="bf27">
<li id="f.vf">Make use of the POJO approach, with lightweight frameworks like <em>Hibernate</em> for <em>ORM<strong> </strong></em>and <em>Spring AOP<strong> </strong></em>for transactional activities.</li>
<li id="wu88"><em>EJB 3</em><strong> </strong>makes it possible to have your business logic sit within your POJO and also make it run outside the container which makes it really usable.</li>
<li id="n-vc">Implementing 3 tiers for an application which commonly include
<ol id="a5tp">
<li id="g.z0">Presentation tier</li>
<li id="c-e:">Business Interfaces for encapsulation + Business tier logic in classes</li>
<li id="cn3y">Persistence tier for handling transactions and concurrency</li>
</ol>
</li>
<li id="b68b">The design should involve,
<ol id="s0hb">
<li id="ywtd">Modeling your business classes appropriately</li>
<li id="q1.l">Code structuring principles for easier maintenance <br id="iuhx" /></li>
</ol>
</li>
</ol>
<p>While the above points are usually very well known amongst the developer community, it helps if you know which decisions should be taken when. Design patterns which have been established over the years play a key role in making such decisions. The white paper explains a few of the design patterns which are particularly mentioned when enterprise applications are into consideration.</p>
<p>I would like to enumerate here, some of the different design patterns which are highlighted in the paper, according to the decisions which fall into 3 main categories.</p>
<p><strong id="k87:"><span style="text-decoration: underline;">Decision #1 &#8211; Organizing Business Logic</span></strong></p>
<p>When you have to implement the business logic it is very important to identify the scope and the scale of the application to decide one or the other approaches as stated below,</p>
<p><strong id="qc0o">Transaction Script Pattern:</strong><br id="kvzb" /></p>
<ol id="v2-6">
<li id="qb0w">Does not follow the object oriented principles</li>
<li id="g:v:">Methods are mapped to application request from the presentation tier, which are called as Transaction Scripts</li>
<li id="e-6a">Follows the procedural approach which makes <em>classes</em> less important and <em>methods</em> more important</li>
<li id="jfs0">Simple to implement but difficult to understand and maintain the code</li>
<li id="jmy8">Mainly used when business application is small</li>
</ol>
<p><strong id="jq6k">Object Oriented Approach:</strong><br id="hr43" /></p>
<ol id="rth0">
<li id="x289">Maps the objects from real world to the application</li>
<li id="zz9v">Easier to understand the application logic</li>
<li id="c6vw">Behavior and state are encapsulated inside the mapped objects</li>
<li id="x3-k">Lightweight frameworks help to apply this approach to your application.</li>
</ol>
<p><strong id="wnku">Table Module Pattern:<br id="q923" /></strong></p>
<ol id="o9m8">
<li id="uyut">Involves mapping of <em>database tables</em> to <em>business classes</em></li>
<li id="u5ni">An object of a table includes all rows of the table rather than a single object mapped to one row</li>
<li id="rrpc">It suffers from the problem of maintenance.</li>
</ol>
<p><br id="kh1t" /><strong id="u5bl"><span style="text-decoration: underline;">Decision #2 &#8211; Encapsulating of Business Logic</span></strong><br id="ox2p" /><br />
Well designed Business applications always encapsulate logic from the view. This helps in application scalability and security, at the same time providing loose coupling between the different tiers. The patterns which can be adhered to encapsulate business logic are:<br />
<br id="puy-" /><strong id="kh-i">Session Facade Pattern:<br id="f5_l" /></strong></p>
<ol id="g5hb">
<li id="y0_t">Promotes proper encapsulation of business level logic</li>
<li id="i4w2">Handles transactional behavior, security and presentation tier requests</li>
<li id="ztw0">Does caching of objects to prevent memory overloading in case of many requests</li>
<li id="t_3n">Delegates requests to proper business objects</li>
<li id="v-xx">Was earlier implemented by using EJB 2 Session Objects</li>
<li id="ub:t">It is heavy on memory and time consuming for testing and development</li>
</ol>
<p><strong id="w8ez">POJO Facade Pattern:<br id="fs4_" /></strong></p>
<ol id="h_e5">
<li id="neqw">Business logic encapsulated within simple <strong>POJO&#8217;s</strong></li>
<li id="r7-b">Easier to develop and test and can run outside the container</li>
<li id="cr3b">Transactions , security and state can be maintained through <strong>AOP</strong></li>
<li id="serv"><strong>Spring framework</strong> uses this pattern</li>
<li id="mm4x">Light on memory</li>
<li id="lk7t">Makes use of <strong>Dependency Injection</strong> for wiring the <em>business classes</em> instead of using <em>JNDI</em><br id="ch4d" /></li>
</ol>
<p><strong id="zc99">Exposed Domain Model Pattern:<br id="zy0q" /></strong></p>
<ol id="tmgf">
<li id="l9v3">Used to avoid extra code for designing the facade</li>
<li id="h5-o">Presentation tier can <strong>directly</strong> access data objects <br id="schn" /></li>
<li id="ocwk">Makes use of <strong>AOP</strong> to access business objects without an intermediate facade layer</li>
<li id="i33w">Drawbacks include the requirement of transactions and data handling by presentation tier</li>
<li id="i33w">Risky since presentation tier can directly manipulate persistent data.</li>
</ol>
<p><br id="ed-o" /><strong id="i566"><span style="text-decoration: underline;">Decision #3 &#8211; Database Access</span></strong><br id="dn0:" /></p>
<p>The decision of accessing data is of strategic importance since IO has a major impact on application performance. So apart from making a decision on the databases and normalization it is crucial to have the best approach for accessing it from other tiers in the application. The paper emphasizes that,</p>
<p><strong>Direct JDBC</strong> has drawbacks such as:<br id="ucjy" /></p>
<ol id="pcb3">
<li id="q55_">Boiler plate code for handling connection and fetching of data</li>
<li id="pm-v">Database specific SQL reduces the portability of the application</li>
<li id="rlt:">Maintenance of low level SQL poses problems from schema changes</li>
<li id="z1.9">Can be of advantage when vendor specific features have to be accessed</li>
</ol>
<p>To overcome the disadvantages of JDBC, using a framework like the <strong id="i1sy">iBATIS Framework </strong>can be advantageous since:<br id="kwql" /></p>
<ol id="k_bx">
<li id="m.3_">Direct SQL queries can be used <br id="t-hn" /></li>
<li id="elp1">Provides mapping between resultsets and Java Beans through XML descriptor</li>
</ol>
<p>The Advantages that <strong id="gc:b">Persistance Frameworks</strong> offer are:<br id="vm2_" /></p>
<ol id="r.0g">
<li id="lywi">Mapping of data to domain objects</li>
<li id="b:5g"><strong>No need</strong> to write SQL code</li>
<li id="lr-n">Flexibility offered by configuring XML descriptors for domain level objects and data <br id="pk6x" /></li>
<li id="qab1">Loading &amp; updating of database as and when required</li>
<li id="zk7x">Transactions and concurrency are handled by the framework</li>
</ol>
<p>Enterprise applications should be modeled and designed properly from the early phases itself. Without following proper approaches from the ones mentioned above can be an invitation for trouble. I hope that these approaches help the developers to come up with good designs for enterprise applications.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/06/10/design-patterns-building-blocks-for-your-application/" rel="bookmark" title="Permanent Link: Design Patterns &#8211; Building blocks for your application">Design Patterns &#8211; Building blocks for your application</a></li><li><a href="http://techtracer.com/author/" rel="bookmark" title="Permanent Link: Author">Author</a></li><li><a href="http://techtracer.com/2007/04/09/web-and-desktop-apps-the-3rd-world-war/" rel="bookmark" title="Permanent Link: Web and Desktop Apps &#8211; the 3rd World War!">Web and Desktop Apps &#8211; the 3rd World War!</a></li><li><a href="http://techtracer.com/2007/07/22/soa-still-far-from-reality/" rel="bookmark" title="Permanent Link: SOA &#8211; Still Far from Reality">SOA &#8211; Still Far from Reality</a></li><li><a href="http://techtracer.com/2007/08/13/java-ee-exhaustive-yet-enchanting/" rel="bookmark" title="Permanent Link: Java EE &#8211; Exhaustive yet Enchanting">Java EE &#8211; Exhaustive yet Enchanting</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/03/30/designing-enterprise-applications-approaches-and-patterns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Key Points for Choosing the Best framework</title>
		<link>http://techtracer.com/2008/03/17/key-points-for-choosing-the-best-framework/</link>
		<comments>http://techtracer.com/2008/03/17/key-points-for-choosing-the-best-framework/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 19:00:56 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Opinions]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/03/17/key-points-for-choosing-the-best-framework/</guid>
		<description><![CDATA[The question which majority of we developers ask always is &#8220;Which framework should I use for my application?&#8221; or &#8220;Which framework is the best to use?&#8221;
The answer to these questions always comes in as &#8220;it depends&#8221; because requirements differ project wise. It might not be the case that the project which you might be working [...]]]></description>
			<content:encoded><![CDATA[<p>The question which majority of we developers ask always is &#8220;<strong>Which framework</strong> should I use for my application?&#8221; or &#8220;Which framework is the <strong>best</strong> to use?&#8221;</p>
<p>The answer to these questions always comes in as &#8220;<strong>it depends</strong>&#8221; because requirements differ project wise. It might not be the case that the project which you might be working on will be requiring the same framework used in the prior projects. Requirements vary all the time and the framework which comes very close for implementing the specified tasks would be the <a href="http://blog.thinkrelevance.com/2008/1/11/how-to-pick-a-platform" target="_blank">best framework for you</a>.</p>
<p style="text-align: center"><img src="http://techtracer.com/wp-content/uploads/2008/03/which_frameworks.gif" alt="Frameworks.gif" /></p>
<p>Having said that it is important to list down the <strong>key points</strong> on why you choose a particular framework. It is never a good reason to choose a framework just because others say it is cool. Let us <strong>focus</strong> on the key points for deciding a framework. Keep in mind, I am not trying to impose the usage of suggested framework for any particular project. This is a topic of general discussion in case where you might be eager to try out a new framework but are stuck to the choice of framework to start from.</p>
<p>The key points which might help you to make your choice are (not in any particular order):</p>
<ul>
<li><strong>Popularity</strong>
<ul>
<li>Helps in getting acquainted quickly (eg: Groovy)</li>
</ul>
</li>
<li><strong>Market</strong>
<ul>
<li>Easier to find jobs (eg: <a href="http://firstpartners.net/blog/technology/2006/03/01/web-20-and-enterprise-java-move-over-struts/" target="_blank">Struts</a>)</li>
</ul>
</li>
<li><strong>Convenience</strong>
<ul>
<li>Should not take a huge learning curve (eg: Tapestry)</li>
</ul>
</li>
<li><strong>Time to implement</strong>
<ul>
<li>Should make the task get completed quickly</li>
</ul>
</li>
<li><strong>Scope</strong>
<ul>
<li>Should be pluggable with other frameworks (eg: Spring)</li>
</ul>
</li>
<li><strong>Documentation</strong>
<ul>
<li>Most important without which you will get stuck easily</li>
</ul>
</li>
<li><strong>Forums</strong>
<ul>
<li>The more big the community the easier is your work done</li>
</ul>
</li>
<li><strong>Bug tracking</strong>
<ul>
<li>If at all you tend to go deep, ticketing support should be present</li>
</ul>
</li>
<li><strong>Reference Books</strong>
<ul>
<li>Essential since online searching can eat up your time</li>
</ul>
</li>
<li><strong>Light weight</strong>
<ul>
<li>Complex ones will do no good if is not used much (eg: EJB 2.x)</li>
</ul>
</li>
<li><strong>Robust</strong>
<ul>
<li>There should not be any known bugs for the features you want to implement</li>
</ul>
</li>
<li><strong>Features</strong>
<ul>
<li>Makes good the time spent if <a href="http://www.firstpartners.net/blog/technology/java-server-faces-jsf/2008/03/13/web2-with-javastruts2-spring-mvc-flex-javafx-and-google-web-toolkit/" target="_blank">one is more powerful than the other</a>.</li>
</ul>
</li>
</ul>
<p>These are the <strong>12 key points </strong>which I feel are very<strong> important </strong>when I look forward to work on a self project or am willing to learn a new framework. It is not necessary that all the 10 will be satisfied by <strong>one single</strong> framework. So it would be more beneficial to make a<strong> subset </strong>of these key points for shortlist your choice of frameworks based on your project.</p>
<p><strong>How to finalize on a particular framework?</strong></p>
<p>First, decide on comparing <strong>2 to 3 frameworks </strong>at the max. The more you have in mind, the more confusion it will create. Plan out which features you want to implement for the given set of requirements. Do an exhaustive <a href="http://techtracer.com/2008/01/06/10-most-amazing-google-search-tricks/">search on Google</a> whether the features are provided by the frameworks you have in mind. Give points <strong>out of 10</strong> for each of the subset key points. Compare the  frameworks for the <strong>same subset</strong> of key points.</p>
<p>This will help you to make a <strong>matrix </strong>out of your choices and will further make it much easier to finalize your choice since now you would be sure of the reasons you are making a decision.</p>
<p>What are your key points when you first think when you pick a framework to work upon? It would be an interesting discussion to follow up. How did you shortlist your framework for learning or working on a project?</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/03/26/first-step-in-ajax-choosing-the-right-framework/" rel="bookmark" title="Permanent Link: First step in Ajax &#8211; Choosing the right framework">First step in Ajax &#8211; Choosing the right framework</a></li><li><a href="http://techtracer.com/2007/06/03/the-struts-framework-why-choose-it/" rel="bookmark" title="Permanent Link: The Struts Framework &#8211; Why choose it?">The Struts Framework &#8211; Why choose it?</a></li><li><a href="http://techtracer.com/2007/04/10/optimal-use-of-ajax-use-web-20-the-smart-way/" rel="bookmark" title="Permanent Link: Optimal use of Ajax &#8211; use Ajax the smart way">Optimal use of Ajax &#8211; use Ajax the smart way</a></li><li><a href="http://techtracer.com/2007/03/27/ajax-frameworks-server-side-versus-client-side/" rel="bookmark" title="Permanent Link: Ajax Frameworks &#8211; Server side versus Client side">Ajax Frameworks &#8211; Server side versus Client side</a></li><li><a href="http://techtracer.com/2007/08/28/what-do-you-dream-for-in-an-ide/" rel="bookmark" title="Permanent Link: What Do You Dream For In An IDE?">What Do You Dream For In An IDE?</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/03/17/key-points-for-choosing-the-best-framework/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Implementing Websites For Internationalization</title>
		<link>http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/</link>
		<comments>http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 16:05:52 +0000</pubDate>
		<dc:creator>ninadgawad</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/</guid>
		<description><![CDATA[Most business in today’s open market are demanding their websites &#38; web application to have multilingual support. This is in order to attract non-English speaking audiences to increase their customer base and make people comfortable using the application in their native language. But for this, it would require an existing business application to be customized [...]]]></description>
			<content:encoded><![CDATA[<p>Most business in today’s open market are demanding their websites &amp; web application to have multilingual support. This is in order to attract non-English speaking audiences to increase their customer base and make people comfortable using the application in their native language. But for this, it would require an existing business application to be customized to support native locale. The process of producing an application that can be localized for a particular country without any changes to the program code is called <strong>Internationalization</strong>.</p>
<p style="text-align: center"><img src="http://techtracer.com/wp-content/uploads/2008/03/internationalization.gif" alt="Internationalization" /></p>
<p>Following are the list of things one needs to take care while making an application to implement Internationalization.</p>
<p><strong>1. Producing Content in Unicode </strong></p>
<p>You need to make sure that all files which contain the multilingual  content are in <strong>Unicode format</strong>. By default most text editors will store your file in <strong>ASCII</strong> which does not support other language characters. So after saving any content in ASCII format and loading it, your browser might not be able to display correct text in native language. Here you need to convert the file from ASCII to UTF format.</p>
<p>For example, the steps required for doing this if you are using Notepad are,</p>
<ul>
<li>Open your JavaScript or properties, etc. file in notepad</li>
<li>Go to &gt; File &gt; Save As &gt; Encoding</li>
<li>Change Encoding from ASCII to UTF-8</li>
</ul>
<p><strong>2. Files needed to be converted to UTF</strong></p>
<p><u><em><strong> .properties</strong></em></u></p>
<p>All your properties file should have a suffix based on the language in which the content is stored in this file. For example,</p>
<ul>
<li>For English, <strong>content_en.properties</strong> for French <strong>content_fr.properties </strong>and so on.</li>
<li>Most java frameworks like Struts, Spring have inbuilt support to detect JVM locale and select the corresponding properties file based on the extension of the file &amp; JVM/Browser setting. You don&#8217;t need to add any code to detect the setting and set the properties file</li>
</ul>
<p><u><em><strong>.java</strong></em></u></p>
<p>Make sure that your JVM has set the parameter <strong>-Dfile.encoding=UTF-8</strong></p>
<p><u><em><strong>.js</strong></em></u></p>
<p>Set charset attribute of the SCRIPT tag to &#8220;UTF-8&#8243;. For example,</p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221; src=&#8221;./urscript.js&#8221; <strong>charset=&#8221;UTF-8&#8243;</strong>&gt;&lt;/script&gt;</p></blockquote>
<p><u><em><strong>.xml</strong></em></u></p>
<p>Use the steps as in the first example to make sure the content within the XML files in is UTF-8 format.</p>
<p><u><em><strong>.html/.htm</strong></em></u></p>
<p>Add this line to head of all html pages.</p>
<blockquote><p>&lt;meta name=&#8221;http-equiv&#8221; content=&#8221;Content-type: text/html; <strong>charset=UTF-8</strong>&#8220;/&gt;</p></blockquote>
<p><u><em><strong>.jsp</strong></em></u></p>
<p>Set Content-type explicitly through your server side scripts. To do this, add this line to all your jsp pages,</p>
<blockquote><p>&lt;%@page contentType=&#8221;text/html; <strong>charset=UTF-8</strong>&#8221; pageEncoding=&#8221;UTF-8&#8243;%&gt;</p></blockquote>
<blockquote></blockquote>
<p><strong>3. Configuring the Web Server</strong></p>
<p>Your Web Server has to be configured to set the Content-type of headers to UTF-8 since by default the web server will replace the Content-type-header to ISO-8859 encoding. For example:</p>
<ul>
<li>In Apache Web Server, edit <strong>httpd.conf</strong> to set <strong>AddDefaultCharset=Off</strong>.</li>
<li>In Tomcat Server set connector settings within the <strong>server.xml</strong> file to <strong>URIEncoding=&#8221;UTF-8&#8243;</strong></li>
</ul>
<p><strong>4. Handling Request &amp; Response Objects</strong></p>
<p>Make sure that before reading request parameters &amp; writing to response objects set character encoding type to UTF-8. This can be handled using <strong>filters</strong> where all the contents coming in and going out can be set to UTF-8 encoding. For example,</p>
<ul>
<li>request.setCharacterEncoding(&#8220;UTF-8&#8243;);</li>
<li>response.setContentType(&#8220;text/html&#8221;);</li>
<li>response.setCharacterEncoding(&#8220;UTF-8&#8243;);</li>
</ul>
<p><strong>5. Creating Database with Unicode encoding</strong></p>
<p>While using a database make sure that the database created has encoding set to UNICODE. Most of the database servers like Oracle, Postgress, MySQL and MSSQL have this support. In order to create databases with unicode encoding use the following query,</p>
<blockquote><p>CREATE DATABASE MyWebApps DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;</p></blockquote>
<p>Once all the above steps are implemented your web application will work smoothly for all UTF-8 supported languages. In some cases, you will have to take care of <a href="http://java.sun.com/docs/books/tutorial/i18n/format/numberFormat.html" target="_blank">NumberFormat</a>, <a href="http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html" target="_blank">DecimalFormat</a> and <a href="http://java.sun.com/docs/books/tutorial/i18n/format/dateFormatSymbols.html" target="_blank">DateFormat</a>. There are some <a href="http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp" target="_blank">FAQ&#8217;s on internationalization provided by Sun</a> to get you started. But feel free to put in your doubts related to internationalization via comments. I will be glad to help you out.</p>
<p><em>(<strong>Ninad Gawad</strong> is a Java EE Developer who blogs at <a href="http://ninadgawad.wordpress.com/" target="_blank">Technology Discussion</a>)</em></p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/12/26/techtracer-20-is-coming/" rel="bookmark" title="Permanent Link: Techtracer 2.0 is Coming">Techtracer 2.0 is Coming</a></li><li><a href="http://techtracer.com/2008/02/16/power-of-xray-for-web-designers/" rel="bookmark" title="Permanent Link: Power of XRAY for Web Designers">Power of XRAY for Web Designers</a></li><li><a href="http://techtracer.com/2007/11/05/feast-your-eyes-with-firefox-piclens/" rel="bookmark" title="Permanent Link: Feast Your Eyes With Firefox Piclens">Feast Your Eyes With Firefox Piclens</a></li><li><a href="http://techtracer.com/2007/06/03/the-struts-framework-why-choose-it/" rel="bookmark" title="Permanent Link: The Struts Framework &#8211; Why choose it?">The Struts Framework &#8211; Why choose it?</a></li><li><a href="http://techtracer.com/2007/07/30/plagiarism-black-listing-of-sites-is-a-must/" rel="bookmark" title="Permanent Link: Plagiarism &#8211; Black Listing of Sites is a Must">Plagiarism &#8211; Black Listing of Sites is a Must</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Effects of Oracle BEA Acquisition</title>
		<link>http://techtracer.com/2008/01/23/effects-of-oracle-bea-acquisition/</link>
		<comments>http://techtracer.com/2008/01/23/effects-of-oracle-bea-acquisition/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 17:02:15 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Opinions]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/01/23/effects-of-oracle-bea-acquisition/</guid>
		<description><![CDATA[With the news of mergers happening here and there round the globe the developer community is not far from getting affected. The latest news of Oracle and BEA acquisition  is bound to leave developers amidst some sort of uncertainty as to why has this taken place at all and what effects will it have [...]]]></description>
			<content:encoded><![CDATA[<p>With the news of mergers happening here and there round the globe the developer community is not far from getting affected. The latest news of Oracle and BEA acquisition  is bound to leave developers amidst some sort of uncertainty as to why has this taken place at all and what effects will it have on them.</p>
<p style="text-align: center"><img src="http://techtracer.com/wp-content/uploads/2008/01/oracle-bea.gif" alt="Oracle acquires BEA" /></p>
<p><strong>BEA</strong> is known for its well diversified technology stack of <strong>Weblogic</strong> Java Application Servers, SOA products and the <strong>Aqualogic</strong> suite of ESB and BPM products. Also to mention that BEA holds a strong integration of all the above suites into its Weblogic Workshop which has been built around the Eclipse platform.</p>
<p><strong>Oracle</strong> on the other hand too has an array <a href="http://soa-talk.blogs.techtarget.com/2008/01/16/oracle-buys-bea-now-the-hard-work-begins/" target="_blank">of  similar products</a> including Appservers, ESB, SOA and BPM. Then the question arises as to why Oracle is acquiring BEA? Some insights to the things apart from the product suites clash should be taken in consideration here to understand Oracle&#8217;s point of view.</p>
<p><a href="http://www.oracle.com/corporate/press/2008_jan/bea.html" target="_blank">Oracle entered into an acquisition with BEA Systems</a> after it offered <strong>$19.375/share</strong> which is nearly a <strong>40%</strong> premium over the October 2007 price when Oracle had done its first bid. This can be seen as a state of urgency on the part of Oracle to acquire BEA. Some speculation can be allotted on to the latest SOA offerings of BEA which could have made Oracle think for a big upgradation in their services.</p>
<p>Thinking other ways, Oracle might just be preparing for a tussle with the other giants such as <strong>IBM</strong> and <strong>SAP</strong> for gaining the market share in providing <strong>SOA infrastructure</strong>. With the BEA acquisition, Oracle will be in ready position to flash a list of clientele from BEA&#8217;s portfolio  to match with the competitors. With the <a href="http://www.infoworld.com/article/07/09/11/bea-genesis_1.html" target="_blank">future plans of BEA for SOA</a>, Oracle&#8217;s merger plans must have been really thought out.</p>
<p>It might be also a case of killing the competition. Big players often tend to downsize the smaller fish by making them surrender. This can be a case with Oracle too. Having a chance to get the customer base from BEA, it can simply kill off the competition by either junking off all BEA products off the line or by <a href="http://www.infoworld.com/article/08/01/16/Oracleandbea_1.html" target="_blank">carefully integrating BEA products with its middleware</a> and offering separate flagship services, just as it has done after acquiring PeopleSoft and JDEdwards.</p>
<p>Organizations today are keen to have a single suite of products to manage their businesses and <strong>middleware</strong> competition is on the rise. This probably makes Oracle&#8217;s target to claim for a <a href="http://money.cnn.com/news/newsfeeds/articles/djf500/200801161631DOWJONESDJONLINE001087_FORTUNE5.htm" target="_blank">one vendor many solutions</a> more justified. But for the developers its more than a platform choice because now it would be choosing between their career paths too. I also have worked on Weblogic App server with Oracle database as the backend. With this acquisition, developers like me will have to decide on which path to opt for.</p>
<p>If Oracle junks off BEA products for killing the competition it might give rise for fear within the Weblogic community. Hopefully, if Oracle makes a decision of providing a flagship line of BEA products, the developer community will be more than happy to flash the name of Oracle on their resumes. This will be clear only in the <strong>mid of 2008 </strong>when the acquisition will be completed. The major question now lies as to what would a Java EE developer do in such a situation?</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/03/10/5-most-exciting-search-tricks-with-google-operators/" rel="bookmark" title="Permanent Link: 5 Most Exciting Search Tricks with Google Operators">5 Most Exciting Search Tricks with Google Operators</a></li><li><a href="http://techtracer.com/2008/05/11/bea-dev2dev-techdays-an-experience/" rel="bookmark" title="Permanent Link: BEA Dev2Dev TechDays &#8211; An Experience">BEA Dev2Dev TechDays &#8211; An Experience</a></li><li><a href="http://techtracer.com/2008/06/15/best-tools-for-editing-your-photos-online/" rel="bookmark" title="Permanent Link: Best Tools For Editing Your Photos Online">Best Tools For Editing Your Photos Online</a></li><li><a href="http://techtracer.com/2007/05/13/why-sybase-is-similar-to-microsofts-sql-server/" rel="bookmark" title="Permanent Link: Why Sybase is similar to Microsoft&#8217;s SQL Server">Why Sybase is similar to Microsoft&#8217;s SQL Server</a></li><li><a href="http://techtracer.com/2007/06/10/design-patterns-building-blocks-for-your-application/" rel="bookmark" title="Permanent Link: Design Patterns &#8211; Building blocks for your application">Design Patterns &#8211; Building blocks for your application</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/01/23/effects-of-oracle-bea-acquisition/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>uCertify SCWCD PrepKit &#8211; Detailed Review</title>
		<link>http://techtracer.com/2008/01/16/ucertify-scwcd-prepkit-detailed-review/</link>
		<comments>http://techtracer.com/2008/01/16/ucertify-scwcd-prepkit-detailed-review/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 15:54:06 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/01/16/ucertify-scwcd-prepkit-detailed-review/</guid>
		<description><![CDATA[uCertify had asked me to do a review on their latest offering of exam simulators called PrepKit, and this article therefore is an outcome of the review process I did for it. In this instance I have taken the SCWCD PrepKit since I already had an experience of JWeb Plus and Whizlabs simulators while preparing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ucertify.com/" target="_blank">uCertify</a> had asked me to do a review on their latest offering of exam simulators called <strong>PrepKit</strong>, and this article therefore is an outcome of the review process I did for it. In this instance I have taken the <strong>SCWCD PrepKit</strong> since I already had an experience of <strong>JWeb Plus</strong> and <strong>Whizlabs </strong>simulators while preparing for the <a href="http://techtracer.com/2007/07/10/scwcd-the-3-steps-to-success/">SCWCD examination</a>.</p>
<p style="text-align: center"><a href="http://www.ucertify.com/" target="_blank"><img src="http://www.ucertify.com/themes/default/logo.gif" alt="uCertify Logo" title="uCertify Logo" /></a></p>
<p><a href="http://www.ucertify.com/exams/SUN/CX310-081.html" target="_blank">uCertify SCWCD PrepKit</a> comes forward as a breath of fresh air to break away the eeriness which comes to people while facing a exam. The look of the PrepKit is unique and new such that it compels us to explore more than the PrepKit itself. The practice exams are of course are the major highlights as it should be, but the features complimenting them come with a surprisingly elegant experience.</p>
<p style="text-align: center"><a href="http://techtracer.com/wp-content/uploads/2008/01/ucertify_scwcd_simulator_large.jpg" target="_blank"><img src="http://techtracer.com/wp-content/uploads/2008/01/ucertify_scwcd_simulator.jpg" alt="ScreenShot of uCertify SCWCD Simulator" /></a></p>
<p><strong>uCertify PrepKit Features</strong></p>
<p>uCertify has done a commendable effort in putting together a product in making the user to develop a liking for the exam experience. The PrepKit acts like a tutor in cases you have a difficulty in answering. After using uCertify PrepKit you would feel as you have got more than what you were expecting. These reactions are not only mine but also of those people whom I have shown this PrepKit.</p>
<p>The features of uCertify include:</p>
<ol>
<li>4 practice exams</li>
<li>One final exam (which might be saved for the D day)</li>
<li>Adaptive tests</li>
<li>Customized tests (These are of great use)</li>
<li>Test History</li>
<li>Readiness Reports</li>
</ol>
<p><strong>Mock Exams</strong></p>
<p>Each of the practice tests contains a number of <strong>45 questions</strong>. I am not quite sure why they chose 45 questions when the exam should contain a set of<strong> 60 questions</strong>. The final exam consists of 40 questions. The difficulty level of the questions is somewhat <strong>easier</strong> than other simulators such as Whiz labs or JWeb Plus. They very well cover the basic aspects of all the topics. If I compare them to the exam questions, they are almost of same nature.</p>
<p>I have contacted uCertify myself to check on the issue of 45 questions and they did reply to me saying that the PrepKit was just in the preliminary stages. If that’s the case then you should watch out for the future releases.</p>
<p><strong>Readiness Reports</strong></p>
<p>The reports show the percentages you have scored in each of the tests including the custom tests. The likeable feature in this is that the reports allow you to get a <strong>retest</strong> done based on the categories. The categories include:</p>
<ul>
<li>Answered wrong</li>
<li>Answered right</li>
<li>Un attempted</li>
<li>All questions</li>
</ul>
<p><strong>User Interface</strong></p>
<p>When I opened the PrepKit the UI impressed me the most. It has a special feel of user friendliness. It is great in usability perspective and I would attribute another adjective to its aspect, which is “helpful”. This means that the PrepKit at all times keeps you aware of where you might have gone wrong and to where you should correct yourself.</p>
<p>Apart from the above features, uCertify comes packed with a bunch of nice features. I am separating out these features from the above ones because I have not found such features in other PrepKits. These are:</p>
<ol>
<li>Study Articles</li>
<li>Tagging, Book marking, Rating</li>
<li>Interactive Quiz</li>
<li>Flash Cards</li>
</ol>
<p><strong>Special Features</strong></p>
<p>The PrepKit has some special features such as tagging, rating of questions and book marking which can prove to be very effective. These 3 features appear in all places such as while giving the test or while going through the <strong>flash cards</strong>. So when you tag or rate a particular topic you would become more confident when you witness it again in a test or while revising.</p>
<p><strong>Interactive Quiz</strong></p>
<p>You don’t have to wait to finish with your preparation to give exams. This PrepKit comes with an interactive quiz feature. In this, all topics of the syllabus have a set of <strong>12 questions </strong>each. You can choose combinations of the topics which you want the quiz to be based on. In this way, you can skip the topics you haven’t prepared and take a quiz. Based on the quiz results you can decide if you are well prepared in those chosen topics or not. You can also set a<strong> timer</strong> for each question. In my opinion this interactive quiz comes best when you don’t have the time to give a full length test.</p>
<p><strong>Study Articles</strong></p>
<p>You get Study articles as yet another feature. All the topics have been covered and there are in all <strong>196 articles</strong> to read from. This feature serves the best as a <strong>last day preparation</strong>. The articles and very concise and provide many examples. They cover all those aspects which are very essential to remember.</p>
<p><strong>Flash Cards</strong></p>
<p>You must have seen flash cards. You may have used them to remember difficult words in English. But here you can find them in this PrepKit for remember the core concepts for SCWCD. The flash cards are based on the study articles so it might be helpful if you try to remember through flash cards after you have been through the Study articles.</p>
<p><strong>Tagging / Rating / Bookmarking</strong></p>
<p>The best part of tagging questions is that they can be used while creating a <strong>custom test</strong> too. Suppose you <strong>tag </strong>certain questions or topics as “difficult “ either while giving a quiz, reading flash cards or giving a test, then all these tagged questions can be clubbed together to form a new custom test. Doesn’t that sound interesting?</p>
<p>The same is the case for rating where you can <strong>rate </strong>any question from 1 to 5 stars. One single group can be then formed from the similar rated questions. You can also <strong>bookmark</strong> any question for further reference any time you need.</p>
<p><strong>The all new &#8216;How To&#8217; Feature</strong></p>
<p>Hey you get a bonus too from the<strong> ‘How To’</strong> feature. At present there is a single document which tells you how to go about using <strong>Tomcat</strong>. The document is very well illustrated. It is indeed impressive for an exam PrepKit for including practical know how’s. I hope they include more of such documents.</p>
<p>The current cost of the SCWCD PrepKit is <strong>USD 29.99</strong>. But you can test it with a <a href="http://www.ucertify.com/download/CX310-081.html" target="_blank">demo version</a>. To conclude, I will say that you should definitely give a try to the uCertify PrepKit and check it out for yourself. Even if you are willing to give any exam other than SCWCD, uCertify has a <a href="http://www.ucertify.com/download.html">variety of simulators</a> to choose from.</p>
<p>Finally, wishing you all the best from my side if you are going for <strong>SCWCD</strong>. <img src='http://techtracer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If you have just started with your preparation then you might as well read my <a href="http://techtracer.com/2007/07/10/scwcd-the-3-steps-to-success/">SCWCD preparation plan</a>.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/07/09/scwcd-mission-accomplished-2/" rel="bookmark" title="Permanent Link: SCWCD &#8211; Mission Accomplished 2">SCWCD &#8211; Mission Accomplished 2</a></li><li><a href="http://techtracer.com/2007/07/10/scwcd-the-3-steps-to-success/" rel="bookmark" title="Permanent Link: SCWCD &#8211; The 3 Steps to Success!">SCWCD &#8211; The 3 Steps to Success!</a></li><li><a href="http://techtracer.com/2007/07/23/servlet-30-the-journey-begins-now/" rel="bookmark" title="Permanent Link: Servlet 3.0 &#8211; The Journey Begins Now">Servlet 3.0 &#8211; The Journey Begins Now</a></li><li><a href="http://techtracer.com/2007/10/29/different-people-different-networks-shelfari-and-bottletalk/" rel="bookmark" title="Permanent Link: Different People Different Networks &#8211; Shelfari and BottleTalk">Different People Different Networks &#8211; Shelfari and BottleTalk</a></li><li><a href="http://techtracer.com/2007/07/25/adobe-reader-80-%e2%80%93-fully-loaded/" rel="bookmark" title="Permanent Link: Adobe Reader 8.0 &#8211; Fully Loaded">Adobe Reader 8.0 &#8211; Fully Loaded</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/01/16/ucertify-scwcd-prepkit-detailed-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resolving the &#8220;Unsupported major.minor version 49.0&#8243; Error</title>
		<link>http://techtracer.com/2007/10/10/resolving-the-unsupported-majorminor-version-490-error/</link>
		<comments>http://techtracer.com/2007/10/10/resolving-the-unsupported-majorminor-version-490-error/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 15:38:13 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Issues]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>

		<guid isPermaLink="false">http://techtracer.com/2007/10/10/resolving-the-unsupported-majorminor-version-490-error/</guid>
		<description><![CDATA[Many a times I have come across my friends who get this error and are clueless because this error is not something related to the programming logic neither to the server which shows this error either on accessing a servlet or a service. You have to know that this error comes when a class compiled [...]]]></description>
			<content:encoded><![CDATA[<p>Many a times I have come across my friends who get this error and are clueless because this error is not something related to the programming logic neither to the server which shows this error either on accessing a servlet or a service. You have to know that this error comes when a class compiled on a newer version is being tried to run on an older JVM i.e. If you try to run a JDK 1.5 compiled class in an environment having JRE 1.4 the JRE will give you the error,</p>
<blockquote><p> <strong>Unsupported major.minor version 49.0</strong></p></blockquote>
<p>This error is given because the new features introduced in the newer version of Java are not present in the older version. So you have to be careful for using such class files on older environments. For resolving this error you have to follow some simple tips as follows:</p>
<ol>
<li>Check you java version by running the command <strong>java &#8211; version</strong></li>
<li>Check your environment variable JAVA_HOME and the path associated with it</li>
<li>Check your <strong>server</strong> installation if it was installed on an older version</li>
<li>Check which path exists in the environment entries</li>
</ol>
<p>These are the quick tips you would need to do in order to get rid of the error. Sometimes it may happen that the system which you are using might be loaded with 2 to 3 version of Java and you might be required to work on the newer one. In such cases always there is a <strong>confusion</strong> as to what went wrong and with which version. So if you are left in such crises do the following quick action tips:</p>
<ol>
<li>Edit your <strong>JAVA_HOME</strong> with the latest java home folder path</li>
<li>Edit your <strong>path</strong> variable which might already have been set with older version</li>
<li>For this goto <strong>My Computer</strong> &gt; <strong>Properties</strong> &gt; <strong>Advanced </strong>&gt; <strong>Environment Variables</strong> &gt; <strong>path</strong></li>
<li><strong>Remove</strong> the earlier version path which might be something like <em>&lt;java_installed_path&gt;</em>/bin and<strong> replace</strong> it with newer version path</li>
<li>If your server was installed on a older version of Java and if it not been used then its better to <strong>uninstall</strong> it and then install it after making the above changes.</li>
</ol>
<p><u><strong>Note:</strong></u><strong> </strong>You can check if your server was installed on an older version or not by opening the <strong>startup.bat</strong> of your Tomcat server or any <strong>start up </strong>script of other servers and finding the part where the script itself sets the <strong>JAVA_HOME</strong> variable. If you find that it has been set to a older version then it won&#8217;t do any good just by replacing it with a newer version path. You would ultimately have to reinstall the server as per my understanding.</p>
<p>It would be interesting to know if the same can be resolved without having to reinstall the server. Please suggest some alternatives if you have.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/01/02/wordpress-database-error-table-wp_post2cat-doesnt-exist/" rel="bookmark" title="Permanent Link: Wordpress Database Error &#8211; Table &#8216;wp_post2cat&#8217; doesn&#8217;t exist">Wordpress Database Error &#8211; Table &#8216;wp_post2cat&#8217; doesn&#8217;t exist</a></li><li><a href="http://techtracer.com/2007/07/18/wordpress-error-allowed-memory-size-of-8388608-bytes/" rel="bookmark" title="Permanent Link: Wordpress Error &#8211; &#8220;Allowed memory size of 8388608 bytes&#8221;">Wordpress Error &#8211; &#8220;Allowed memory size of 8388608 bytes&#8221;</a></li><li><a href="http://techtracer.com/2007/08/19/working-with-jax-ws-in-jdk-16/" rel="bookmark" title="Permanent Link: Working With JAX-WS in JDK 1.6">Working With JAX-WS in JDK 1.6</a></li><li><a href="http://techtracer.com/2007/08/01/j2ee-or-jee-java-5-or-java-15-is-sun-crazy/" rel="bookmark" title="Permanent Link: J2EE or JEE, Java 5 or Java 1.5 &#8211; Is SUN Crazy?">J2EE or JEE, Java 5 or Java 1.5 &#8211; Is SUN Crazy?</a></li><li><a href="http://techtracer.com/2008/06/09/3-easy-steps-to-install-mysql-on-windows-xp/" rel="bookmark" title="Permanent Link: 3 Easy Steps to Install MySQL on Windows XP">3 Easy Steps to Install MySQL on Windows XP</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2007/10/10/resolving-the-unsupported-majorminor-version-490-error/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Setting Up SSL on Tomcat In 3 Easy Steps</title>
		<link>http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/</link>
		<comments>http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/#comments</comments>
		<pubDate>Wed, 12 Sep 2007 17:15:40 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/</guid>
		<description><![CDATA[Setting up SSL on Tomcat is easy and you don&#8217;t have to do much for converting your web application to work with the Https protocol. But however, the problem you would find to set up SSL is the documentation available over the web. The documentation source is available on the Apache site but it starts [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up <strong>SSL</strong> on <strong>Tomcat</strong> is easy and you don&#8217;t have to do much for converting your web application to work with the <strong>Https</strong> protocol. But however, the problem you would find to set up SSL is the documentation available over the web. The documentation source is available on the <a href="http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html" target="_blank">Apache</a> site but it starts off good and ends with a lot of confusion. Especially I was confused on the <strong>OpenSSL</strong> part where it says to use OpenSSL.</p>
<p>It might be good in a production environment to use OpenSSL but if you just want to test out SSL with Tomcat alone then it is more than enough to just have your JDK and Tomcat setups. So I would make you walk through the same steps which I did while getting SSL up and running and building a secured web app within a matter of <strong>minutes</strong>.</p>
<p>The things which I have used to setup SSL consists of:</p>
<ul>
<li>JDK 1.6</li>
<li>Tomcat 6</li>
</ul>
<p>Even though I have used the latest version I don&#8217;t see any problems which you might face in carrying out the<strong> same </strong>set of steps for JDK 1.5 which I am about to explain. JDK comes shipped with a <strong>keytool </strong>executable which is required to generate a <strong>keystore</strong>. The keytool can be found in the earlier version of JDK too. The 3 steps which would make you to get started with setting up SSL are:</p>
<ol>
<li>Generating the Keystore file</li>
<li>Configuring Tomcat for using the Keystore file</li>
<li>Configuring your web application to work with SSL</li>
</ol>
<p>Let&#8217;s get this party started now.</p>
<p><strong>1. Generating the KeyStore file</strong></p>
<p>The keystore file is the one which would store the details of the <strong>certificates</strong> necessary to make the protocol secured. Certificates contain the information as to who is the source from which you are receiving the application data and to authenticate whether it is the intended party or not. To make this keystore you would have to use the <strong>keytool</strong>. So open command prompt in Windows or the shell in Linux and type:</p>
<blockquote><p>cd %JAVA_HOME%/bin on Windows</p>
<p>cd $JAVA_HOME/bin on Linux</p></blockquote>
<p>You would land up in the Java bin directory. Now time to run the keytool command. You have to provide some parameters to the command as follows :</p>
<blockquote><p>keytool -genkey -alias <strong>techtracer</strong> -keypass <strong>ttadmin</strong> -keystore <strong>techtracer.bin</strong> -storepass <strong>ttadmin</strong></p></blockquote>
<p>The highlighted words are the ones which you would have to change according to your requirements. But keep one thing in mind that both the <strong>keypass </strong>and <strong>storepass</strong> passwords should be the same. The <strong>.bin</strong> file is actually your keystore file. It would now start a questionnaire. So fill in the <strong>relevant </strong>details accordingly. Look below for a reference as to what to answer for the questions.</p>
<blockquote><p>What is your first and last name?<br />
[Unknown]:  <strong>nitin pai</strong><br />
What is the name of your organizational unit?<br />
[Unknown]:  <strong>home</strong><br />
What is the name of your organization?<br />
[Unknown]:  <strong>techtracer</strong><br />
What is the name of your City or Locality?<br />
[Unknown]:  <strong>mumbai</strong><br />
What is the name of your State or Province?<br />
[Unknown]:  <strong>maharashtra</strong><br />
What is the two-letter country code for this unit?<br />
[Unknown]:  <strong>IN</strong><br />
Is CN=nitin pai, OU=home, O=techtracer, L=mumbai, ST=maharashtra, C=IN correct?<br />
[no]: <strong>yes </strong></p></blockquote>
<p>The command would then conclude. It would make a .bin file with the name you had provided inside the bin directory itself. In my case it was <strong>techtracer.bin</strong> which was located in</p>
<blockquote><p>C:\Program Files\Java\jdk1.6.0_02\bin\</p></blockquote>
<p>Put the .bin file in the <strong>webapps</strong> directory of Tomcat. This is required to avoid the need to give an absolute path of the file in the next step.</p>
<p><strong>2.  Configuring Tomcat for using the Keystore file</strong></p>
<p>Here we would be making some changes to the server.xml file inside tomcat to tell it to use the keystore which was created in the earlier step for configuring SSL. Open the file <strong>server.xml</strong> which can be found as:</p>
<blockquote><p><em>&lt;CATALINA_HOME&gt;</em>/conf/server.xml</p></blockquote>
<p>Now you have to modify it. Find the <strong>Connector</strong> element which has <strong>port=&#8221;8443&#8243;</strong> and uncomment it if already not done. Add two lines. The highlighted lines are the newly added ones.</p>
<blockquote><p>    &lt;Connector port=&#8221;8443&#8243;<br />
maxThreads=&#8221;150&#8243; minSpareThreads=&#8221;25&#8243; maxSpareThreads=&#8221;75&#8243;<br />
enableLookups=&#8221;true&#8221; disableUploadTimeout=&#8221;true&#8221;<br />
acceptCount=&#8221;100&#8243; debug=&#8221;0&#8243; scheme=&#8221;https&#8221; secure=&#8221;true&#8221;<br />
clientAuth=&#8221;false&#8221; sslProtocol=&#8221;TLS&#8221;<br />
<strong> keystoreFile</strong>=&#8221;../webapps/techtracer.bin&#8221;<br />
<strong>keystorePass</strong>=&#8221;ttadmin&#8221; /&gt;</p></blockquote>
<p>You can notice that I have given the path to the keystoreFile property as <strong>relative </strong>to tomcat bin directory because the startup command will look for the .bin file. Now all you have to do is start your server and check the working of SSL by pointing your browser to the URL to:</p>
<blockquote><p><strong>https</strong>://localhost:<strong>8443</strong>/</p></blockquote>
<p>Now that you have your tomcat running in the SSL mode you are ready to deploy an application to test its working. You must note that<strong> still</strong> your tomcat can run in normal mode too at the same time i.e on port<strong> 8080</strong> with <strong>http</strong>. So it is but obvious that any application deployed to the server will be running on http and https at the <strong>same time</strong>. This is something that we don&#8217;t want. We want our application to run <strong>only</strong> in the secured mode.</p>
<p><strong> 3. Configuring your web application to work with SSL</strong></p>
<p>In order to do this for our test, take any application which has already been deployed <strong>successfully</strong> in Tomcat and first access it through http and https to see if it works fine. If yes, then open the <strong>web.xml</strong> of that application and just add this XML fragment <strong>before</strong> web-app ends i.e <strong>&lt;/web-app&gt;</strong></p>
<blockquote><p>&lt;security-constraint&gt;<br />
&lt;web-resource-collection&gt;<br />
&lt;web-resource-name&gt;securedapp&lt;/web-resource-name&gt;<br />
&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />
&lt;/web-resource-collection&gt;<br />
&lt;user-data-constraint&gt;<br />
&lt;transport-guarantee&gt;<strong>CONFIDENTIAL</strong>&lt;/transport-guarantee&gt;<br />
&lt;/user-data-constraint&gt;<br />
&lt;/security-constraint&gt;</p></blockquote>
<p>Explanation of the fragment is beyond the scope of this tutorial but all you should notice is that the <strong>/* </strong>indicates that now, any resource in your application can be accessed only with <strong>https</strong> be it Servlets or JSP&#8217;s. The term <strong>CONFIDENTIAL </strong> is the term which tells the server to make the application work on SSL. If you want to turn the SSL mode for this application off then just turn don&#8217;t delete the fragment. Just put the value as <strong>NONE</strong> instead of <strong>CONFIDENTIAL</strong>. That&#8217;s it!</p>
<p><strong>Conclusion</strong></p>
<p>These were the 3 easy steps in which you can make Tomcat to work in the SSL mode and also it tells you how easily you can turn the SSL mode on and off. If you find any difficulty or are not clear on any of the above steps feel free to drop in your queries. If you like this tutorial it would be nice of you to drop in a comment of appreciation or feedback as to how this tutorial can be improved.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/" rel="bookmark" title="Permanent Link: The Technique of Virtual Deployment in Tomcat">The Technique of Virtual Deployment in Tomcat</a></li><li><a href="http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/" rel="bookmark" title="Permanent Link: Implementing Websites For Internationalization">Implementing Websites For Internationalization</a></li><li><a href="http://techtracer.com/2008/06/09/3-easy-steps-to-install-mysql-on-windows-xp/" rel="bookmark" title="Permanent Link: 3 Easy Steps to Install MySQL on Windows XP">3 Easy Steps to Install MySQL on Windows XP</a></li><li><a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/" rel="bookmark" title="Permanent Link: The Great Ant Tutorial &#8211; a great jump start">The Great Ant Tutorial &#8211; a great jump start</a></li><li><a href="http://techtracer.com/2007/08/26/eclipse-europa-has-ruined-my-day/" rel="bookmark" title="Permanent Link: Eclipse Europa Has Ruined My Day">Eclipse Europa Has Ruined My Day</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/feed/</wfw:commentRss>
		<slash:comments>174</slash:comments>
		</item>
	</channel>
</rss>
