<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>My Job Experiences</title>
	<atom:link href="http://jobexperiences.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jobexperiences.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 29 Dec 2011 07:33:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jobexperiences.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>My Job Experiences</title>
		<link>http://jobexperiences.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jobexperiences.wordpress.com/osd.xml" title="My Job Experiences" />
	<atom:link rel='hub' href='http://jobexperiences.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Command Class with MultiActionController</title>
		<link>http://jobexperiences.wordpress.com/2009/06/11/command-class-with-multiactioncontroller/</link>
		<comments>http://jobexperiences.wordpress.com/2009/06/11/command-class-with-multiactioncontroller/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 16:54:31 +0000</pubDate>
		<dc:creator>curioushard</dc:creator>
				<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://jobexperiences.wordpress.com/?p=9</guid>
		<description><![CDATA[After writing a post on different types of controllers spring framework provides,  i felt the need of writing a short description of how one can use command class Object while working with MultiActionController. Now got a chance to write few additions in my previous article Why spring provide too many types of controllers As you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jobexperiences.wordpress.com&amp;blog=2162164&amp;post=9&amp;subd=jobexperiences&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After writing a post on different types of controllers spring framework provides,  i felt the need of writing a short description of how one can use command class Object while working with MultiActionController. Now got a chance to write few additions in my previous article <a class="aligncenter" title="Spring Controllers" href="http://jobexperiences.wordpress.com/2007/12/14/why-spring-provides-too-many-types-of-controllers/" target="_blank">Why spring provide too many types of controllers</a> As you can find the detailed descriptions of all types of controllers from internet or many books, here is a little description of such use.</p>
<p>Its better to read this article after when u have read atleast a part of my previous article on spring controllers that gives a detailed description of usage of MultiActionController.</p>
<p>To use command Class with MultiActionController, we need to configure the controller bean in the same way with all its related dependencies. the only change required is in the related function that will be used when the request is submitted to the controller.</p>
<p>here are the steps to be followed;</p>
<ol>
<li>create a class that must extend MultiActionController and import it from spring MVC bundle.</li>
<li>create a bean with the same class create in step 1.</li>
<li>create a bean with id &#8216;<span style="font-size:10pt;font-family:Arial,sans-serif;">nameResolver</span>&#8216; with class <span style="font-size:10pt;font-family:Arial,sans-serif;">org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver</span></li>
<li><span style="font-size:10pt;font-family:Arial,sans-serif;">map this with controller class. you can consult with </span><a title="Spring Controllers" href="http://jobexperiences.wordpress.com/2007/12/14/why-spring-provides-too-many-types-of-controllers/" target="_blank">Why spring provide too many types of controllers</a></li>
</ol>
<p>these are the same steps that need to be followed whether you use command class with this controller or not.</p>
<p><em><strong>when u create a function on which your request is going to be submitted, you are required to mention  a third parameter of  spacific type of command class for the function with HttpServletRequest and HttpServletResponse parameters respectively. </strong></em>like</p>
<p><span style="font-size:10pt;font-family:Arial,sans-serif;">public ModelAndView modifyClient(HttpServletRequest request, HttpServletResponse response, ClientVO clientVO) throws Exception{</span></p>
<p><span style="font-size:10pt;font-family:Arial,sans-serif;">// clientVO will be available with all the values that are mapped with jsp page. so it can further be used in service layer or whatever you want to do with this to get required output.</span></p>
<p><span style="font-size:10pt;font-family:Arial,sans-serif;">return new ModelAndView(targetPage);<br />
</span></p>
<p><span style="font-size:10pt;font-family:Arial,sans-serif;">}</span></p>
<p><span style="font-size:10pt;font-family:Arial,sans-serif;">You might noticed the difference between usage of command class in SimpleFormController and MultiActionController.</span></p>
<p><span style="font-size:10pt;font-family:Arial,sans-serif;">In first case we use Object class as type of command class but in this case we used the specific type of command class object. so no need to make any conversions to some other class to get its property values.</span></p>
<p><span style="font-size:10pt;font-family:Arial,sans-serif;"><br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jobexperiences.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jobexperiences.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jobexperiences.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jobexperiences.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jobexperiences.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jobexperiences.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jobexperiences.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jobexperiences.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jobexperiences.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jobexperiences.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jobexperiences.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jobexperiences.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jobexperiences.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jobexperiences.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jobexperiences.wordpress.com&amp;blog=2162164&amp;post=9&amp;subd=jobexperiences&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jobexperiences.wordpress.com/2009/06/11/command-class-with-multiactioncontroller/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0f5f18df16c3d376009285069831c33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Curious HARD</media:title>
		</media:content>
	</item>
		<item>
		<title>Hibernate Mapping Mystery</title>
		<link>http://jobexperiences.wordpress.com/2008/05/20/hibernate-mapping-mystery/</link>
		<comments>http://jobexperiences.wordpress.com/2008/05/20/hibernate-mapping-mystery/#comments</comments>
		<pubDate>Tue, 20 May 2008 06:52:56 +0000</pubDate>
		<dc:creator>curioushard</dc:creator>
				<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://jobexperiences.wordpress.com/?p=7</guid>
		<description><![CDATA[Hibernate is a framework that facilitate developers in order to get the maximum benefits of ORM (object/relational mapping is the automated (and transparent) persistence of objects in a Java application to the tables in a relational database, using metadata that describes the mapping between the objects and the database). It eliminates the use of direct [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jobexperiences.wordpress.com&amp;blog=2162164&amp;post=7&amp;subd=jobexperiences&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">Hibernate is a framework that facilitate developers in order to get the maximum benefits of ORM <em>(object/relational mapping is the automated (and transparent) persistence of objects in a Java application to the tables in a relational database, using metadata that describes the mapping between the objects and the database).</em></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">It eliminates the use of direct SQL queries by making application independent of database. Hibernate creates a layer between the application and database so that developers can take full advantage of object orientation with normalized database relations at the back end. Instead of going into the depth of hibernate, I would prefer to dive into the core concept of hibernate <strong><em>mapping</em></strong> <strong><em>between objects and relations;</em></strong> how objects oriented hierarchy can be mapped with relational database.</p>
<p class="MsoNormal" style="text-align:justify;">Hibernate provides different types of mappings according to traditional relational databases. Means traditional foreign key associations can be mapped in different ways using hibernate.</p>
<p class="MsoNormal" style="text-align:justify;"><strong>many-to-one</strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><strong>Let’s start from a scenario; </strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><em>You are required to develop an application that needs list of countries and their respective cities to be displayed wherever needed.</em></p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNoSpacing" style="text-align:justify;">So tables for city and country with their proper associations would be your first priority.</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>1.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->A table named as ‘country’. (The possible attributes can be id (primary key), name and code).</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>2.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->A table named as ‘city’. (The possible attributes can be id (primary key), name, code and an extra attribute let’s call it country_id that will be a foreign key of country table).</p>
<p class="MsoNoSpacing" style="text-align:justify;">And two classed to map with these tables for all required manipulations</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>1.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->A class named Country. (The possible properties can be id, name and code.</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>2.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->A class named City. (The possible properties can be id, name, code and an object of Class Country).</p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNoSpacing" style="text-align:justify;">The hbm documents will be as follows;</p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNoSpacing" style="text-align:justify;"><strong><em>city.hbm.xml</em></strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span style="font-size:10pt;"><span>1.<span> </span></span></span><!--[endif]--><span style="font-size:10pt;">&lt;class name=&#8221;hibernate.example.model.City&#8221; table=&#8221;city&#8221; &gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;">The start of hbm document tells about the class association with database table; each operation with <em>try.hibernate.example.model.City </em>object will affect the <em>city</em> table. This class will be called persistence class for city table as well.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span style="font-size:10pt;"><span>1.<span> </span></span></span><!--[endif]--><span style="font-size:10pt;">&lt;id name=&#8221;id&#8221; column=&#8221;id&#8221;&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><em>Id</em> mapping element will be used to specify the primary key of table.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span style="font-size:10pt;"><span>2.<span> </span></span></span><!--[endif]--><span style="font-size:10pt;"><span> </span>&lt;generator class=&#8221;native&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;">Generator class will tell the hibernate how to define the value for primary key, native means hibernate is restricted to use underlying database id assigning strategy; like if user set primary key as auto increment (in mySQL) then even with hibernate there would be no need to set the primary key, hibernate will automatically check the underlying database strategy and follow the same thing. There are many other options available for <em>generator class. </em>but using <em>native</em> is the simplest and easiest way to let the things done by underlying database instead of hibernate.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">&lt;/id&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span style="font-size:10pt;"><span>4.<span> </span></span></span><!--[endif]--><span style="font-size:10pt;">&lt;property name=&#8221;name&#8221; column=&#8221;name&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;text-indent:0.25in;"><span style="font-size:10pt;">&lt;property name=&#8221;code&#8221; column=&#8221;code&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;">Property mapping element will be used to map all those properties of <strong><em>City</em></strong> object that user want to process using object. Like only those attributes of table will be available in object that will be mapped with object properties. And if there is any property mapping for which table column does not exist then hibernate will throw an Exception. There are many attributes available for property mapping elements for different purposes. You may consult <em>Hibernate in Action</em> for more details.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;">The property tag has many other attributes as well. This is the simplest way to map properties with columns. You can use as many attributes as you like.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span style="font-size:10pt;"><span> 5.<span> </span></span></span><!--[endif]--><span style="font-size:10pt;">&lt;many-to-one name=&#8221;country&#8221; column=&#8221;countryId&#8221; <span> </span></span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221;try.hibernate.example.model.Country&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><em>many-to-one</em> relationship in city hbm is defined as</p>
<p class="MsoNoSpacing" style="margin-left:58.5pt;text-align:justify;text-indent:-0.5in;"><!--[if !supportLists]--><span><span>i.<span> </span></span></span><!--[endif]--><em>‘country_id’</em> is a foreign key of country table (defined as column) and</p>
<p class="MsoNoSpacing" style="margin-left:58.5pt;text-align:justify;text-indent:-0.5in;"><!--[if !supportLists]--><span><span>ii.<span> </span></span></span><!--[endif]--><em>‘country’</em> is an object of country in city Class as a representative of foreign key relationship at object level.</p>
<p class="MsoNoSpacing" style="margin-left:58.5pt;text-align:justify;text-indent:-0.5in;"><!--[if !supportLists]--><span><span>iii.<span> </span></span></span><!--[endif]--><em>try.hibernate.example.model.Country</em> is the class name for Country Object.</p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/class&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;/hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNoSpacing" style="text-align:justify;"><strong><em>City.java</em></strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">Class City implements Serilizable { </span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private long id; <span> </span>//identifier property (primary key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private String name;<span> </span>//city name</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private String code;<span> </span>//city code</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private Country country; <span> </span>//referenced object (foreign key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"> // all the properties will have getter and setters as we define properties with private access specifier.</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">}</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> </span>Hibernate doesn’t require that persistent      classes implement <span>Serializable</span>.      However, when objects are stored in an <span>HttpSession </span>or passed by value using RMI, serialization is      necessary. (This is very likely to happen in a Hibernate application.)</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;margin:0 0 0.0001pt 0.5in;">
<ol style="margin-top:0;" type="a">
<li class="MsoNormal">Unlike the JavaBeans specification, which      requires no specific constructor, Hibernate requires a constructor with no      arguments for every persistent class. Hibernate instantiates persistent      classes using <span>Constructor.newInstance()</span>,      a feature of the Java reflection API. The constructor may be non-public,      but it should be at least package-visible if runtime-generated proxies will      be used for performance optimization.</li>
</ol>
<p class="MsoNoSpacing" style="text-align:justify;">The above city hbm document tells everything about the city object as well as about associated city table. Means that <em>try.hibernate.example.model.City<strong> </strong></em>class will be mapped with <em>city</em> table<span style="font-size:10pt;">; </span></p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>a.<span> </span></span></span><!--[endif]-->having primary key name (as defined in underlying database -<span> </span>primary key should be set to <em>auto increment</em>)</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>b.<span> </span></span></span><!--[endif]--><em>name</em> and <em>code</em> as properties mapped with name and code columns of associated city table.</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>c.<span> </span></span></span><!--[endif]--><em>many-to-one</em> relationship with country table that is associated using foreign key relationship.</p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNoSpacing" style="text-align:justify;">Up to this point the mappings defined is unidirectional for city object with associated country object. So while working on city objects you can get the country information to which this city belongs to.</p>
<p class="MsoNoSpacing" style="text-align:justify;">On the other hand if you want to get all the cities of some country then you need to define bidirectional mapping; so the country hbm would look like this;</p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNoSpacing" style="text-align:justify;"><strong><em><span style="font-size:10pt;">country.hbm.xml</span></em></strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;class name=&#8221; hibernate.example.model.County&#8221; table=&#8221;country&#8221; &gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;id name=&#8221;id&#8221; column=&#8221;id&#8221;&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span><span> </span>&lt;generator class=&#8221;native&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/id&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;property name=&#8221;name&#8221; column=&#8221;name&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;property name=&#8221;code&#8221; column=&#8221;code&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span></span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;set name=&#8221;cities&#8221; inverse=&#8221;true”&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;key column=&#8221;country_id&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;one-to-many class=&#8221; try.hibernate.example.model.City&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/set&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/class&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;/hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><strong><em><span style="font-size:10pt;">Country.java</span></em></strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">Class Country implements Serializable{</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private long id; <span> </span>//identifier property (primary key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private String name;<span> </span>//city name</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private String code;<span> </span>//city code</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private Set cities;<span> </span>// collection of cities mapped with set collection </span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">// all the properties will have getter and setters as we define properties with private access specifier.</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">}</span></p>
<ol style="margin-top:0;" type="a">
<li class="MsoNormal">Hibernate requires interfaces for collection-typed      attributes. You must use <span>java.util.Set </span>rather than <span>HashSet</span>,      for example. At runtime, Hibernate wraps the <span>HashSet </span>instance with an instance of one of Hibernate’s      own classes. (This special class isn’t visible to the application code).      It is good practice to program to collection interfaces, rather than      concrete implementations, so this restriction shouldn’t bother you.</li>
</ol>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNoSpacing" style="text-align:justify;">This hbm document define collection of cities related to the country, and I think up till this level things look self explanatory,</p>
<p class="MsoNoSpacing" style="margin-left:0.75in;text-align:justify;text-indent:-0.5in;"><!--[if !supportLists]--><span><span>i.<span> </span></span></span><!--[endif]--><em>key column</em> define the column name in city table that is foreign key of associated country table.</p>
<p class="MsoNoSpacing" style="margin-left:0.75in;text-align:justify;text-indent:-0.5in;"><!--[if !supportLists]--><span><span>ii.<span> </span></span></span><!--[endif]-->One-to-many mapping element defines that this collection will be of <em>city</em> objects.</p>
<p class="MsoNoSpacing" style="margin-left:0.75in;text-align:justify;text-indent:-0.5in;"><!--[if !supportLists]--><span><span>iii.<span> </span></span></span><!--[endif]-->The most important thing is the use of inverse=”true”; it needs some explanation,</p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNoSpacing" style="text-align:justify;">Let’s have a closer look at these two hbm documents; one thing is common in this mapping; <strong><em>column=”country_id” </em></strong>defined in many-to-one mapping of city hbm and one-to-many mapping under collection (set) mapping element.</p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">Hibernate detects two different changes to the in-memory persistent instances. From the point of view of the database, just one value must be updated to reflect the changes: the <span>country_id </span>column of the <span>city </span>table.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><span>Hibernate doesn’t transparently detect the fact that the two changes refer to the same database column<em>, </em>so at this point inverse<em> </em>attributes comes in to indicate that this is a bidirectional association.</span> The <span>inverse </span>attribute tells Hibernate that the collection is a mirror image of the many-to-one association on the other side, Without the <span>inverse </span>attribute, Hibernate would try to execute two different SQL statements, both updating the same foreign key column, when we manipulate the association between the two instances. By specifying <span>inverse=&#8221;true&#8221;</span>, we explicitly tell Hibernate which end of the association it should synchronize with the database.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">Up till now all the mapping requirements have been completed. In order to make this mapping work efficiently we need few more concepts to explore.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong>Cascading</strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">You can also achieve <em>transitive persistence</em> using <em>cascading</em> in different forms, which you need in order to finish the mapping of this association. You can use <em>cascade</em> attribute in different forms; the simplest one is <strong><em>cascade=”save-update”</em></strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong><em> </em></strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">The <span>cascade </span>attribute is directional: It applies to only one end of the association.</p>
<ol style="margin-top:0;" type="a">
<li class="MsoNormal">If we use cascade attribute in <em>city’s many-to-one</em> mapping element that      would mean country object will also be saved while saving city object; so      country object will become mandatory to be populated while populating city      object or you will need to set nullable foreign key. Otherwise hibernate      will throw an exception <em>NULL value      cant to inserted into not null column</em> as normally foreign key column      of county for city table does not allow null values to make sure that each      city most belong to some country. The change in mapping will be;</li>
</ol>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;"><span style="font-size:10pt;">&lt;many-to-one name=&#8221;country&#8221; column=&#8221;countryId” cascade=”save-update”</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221; try.hibernate.example.model.Country &#8221; /&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">So the many-to-one mapping will be replaced with this mapping element to get the benefits of cascade.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<ol style="margin-top:0;" type="a">
<li class="MsoNormal">If you use cascade attribute with city      collection mapping in country hbm document that would mean the collection      will also be saved or updated accordingly with country object. The change      would be like this;</li>
</ol>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10.5pt;"> </span><span style="font-size:10pt;"><span> </span>&lt;set name=&#8221;cities” inverse=&#8221;true” cascade=”save-update”&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span><span> </span>&lt;key column=&#8221;country_id&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;one-to-many class=&#8221; try.hibernate.example.model.City&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/set&gt;</span><strong></strong></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong>Fetching Strategies</strong></p>
<p class="MsoNormal" style="text-align:justify;">Hibernate provide different ways to fetch data from object graph. With all other strategies Lazy fetching is the most prominent.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong><em><span style="font-size:10.5pt;">Single point associations</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">For a <span>&lt;many-to-one&gt; </span>or <span>&lt;one-to-one&gt; </span>association, lazy fetching is possible only if the associated class mapping enables proxying. For the <span>country </span>class, we enable proxying by specifying <span>lazy=&#8221;true&#8221;</span>:</p>
<p class="MsoNoSpacing" style="text-align:justify;text-indent:0.25in;"><span style="font-size:10pt;">&lt;class name=&#8221;</span><span style="font-size:10pt;">try.hibernate.example.model.County</span><span style="font-size:10pt;">&#8221; lazy=&#8221;true&#8221;&gt;</span></p>
<p class="MsoNormal" style="text-align:justify;"><span> </span>Recall the <em>many-to-one</em> association from C<span>ity </span>to <span>Country</span>:</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">&lt;many-to-one name=&#8221;country&#8221; column=&#8221;country_id&#8221;<span> </span></span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221; try.hibernate.example.model.Country &#8221; /&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">When you retrieve a <span>city </span>from the database, the association property may hold an instance of a Hibernate <em>generated subclass </em>of <span>country </span>that delegates all method invocations to a different instance of <span>Country </span>that is fetched lazily from the database (this is the more elaborate definition of a Hibernate proxy).</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">As soon as you declared the <span>lazy </span>attribute on <span>Country</span>, any single-point association to <span>Country </span>is proxied and fetched lazily, unless that association overrides the fetching strategy by declaring the <span>outer-join </span>attribute. <em>outer-join</em> allows user to choose different fetching strategies for different associations to the same proxied class.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">As</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">&lt;many-to-one name=&#8221;country&#8221; column=&#8221; country_id &#8220;<span> </span><span> </span>outer-join=”auto/true/false”</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221; try.hibernate.example.model.Country &#8221; /&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong> </strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">There are three possible values for <span>outer-join</span>:</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><span> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong><em><span>outer-join=&#8221;auto&#8221; </span></em></strong>The default. When the attribute isn’t specified; Hibernate fetches according to the associated object. If the associated class has proxying enabled then object will be fetched lazily otherwise object will be fetched eagerly using an outer join.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">i.e. in this case if we enable lazy for Country by <em>lazy=”true”</em> and no outer-join attribute in <em>many-to-one</em> mapping then if you fetch the City object, hibernate returns a subclass of Country (created by hibernate and its hidden from application code) and when you actually fetch the Country by calling its method then Country will be fetched.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">Like this</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">&lt;many-to-one name=&#8221;country&#8221; column=&#8221; country_id &#8220;<span> </span><span> </span></span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221; try.hibernate.example.model.Country &#8221; /&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong><em><span>outer-join=&#8221;true&#8221; </span></em></strong>Hibernate always fetches the association eagerly using an outer join, even if proxying is enabled.</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">i.e. in our case if we set <em>outer-join=”true”</em> attribute in <em>many-to-one</em> mapping then hibernate will eagerly fetch the country Object using an outer join no matter lazy is enabled for Country or not.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">&lt;many-to-one name=&#8221;country&#8221; column=&#8221; country_id” <strong><em>outer-join=”true”</em></strong></span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221; try.hibernate.example.model.Country” /&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong><em><span>outer-join=&#8221;false&#8221;</span></em></strong> Hibernate never fetches the association using an outer join, even if proxying is disabled.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">&lt;many-to-one name=&#8221;country&#8221; column=&#8221; country_id” <strong><em>outer-join=”false”</em></strong></span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221; try.hibernate.example.model.Country” /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNoSpacing" style="text-align:justify;"><strong>Collection</strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">Collection mappings may declare a <span>lazy </span>attribute, an <span>outer-join </span>attribute, neither, or both (specifying both isn’t meaningful). The meaningful options are as follows:</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong><em>Neither attribute specified </em></strong>This option is equivalent <em>to </em><em><span>outer-join=&#8221;false&#8221; lazy=&#8221;false&#8221;</span>.</em> The collection is fetched from the second-level cache or by an immediate extra SQL <span>SELECT</span>. This option is the default and is most useful when the second-level cache is enabled for this collection.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;set name=&#8221;cities” inverse=&#8221;true” cascade=”save-update”&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span><span> </span>&lt;key column=&#8221;country_id&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;one-to-many class=&#8221; try.hibernate.example.model.City&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/set&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong><em><span>outer-join=&#8221;true&#8221; </span></em></strong>Hibernate fetches the association eagerly using an outer join. At the time of this writing, Hibernate is able to fetch only one collection per SQL <span>SELECT</span>, so it isn’t possible to declare multiple collections belonging to the same persistent class with <span>outer-join=&#8221;true&#8221;</span>.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;set name=&#8221;cities” inverse=&#8221;true” cascade=”save-update” <strong><em>outer-join=”true”</em></strong>&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span><span> </span>&lt;key column=&#8221; country_id&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;one-to-many class=&#8221; try.hibernate.example.model.City&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/set&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong><em><span>lazy=&#8221;true&#8221; </span></em></strong>Hibernate fetches the collection lazily, when it’s first accessed.<strong></strong></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;set name=&#8221;cities” inverse=&#8221;true” cascade=”save-update” <strong><em>lazy=”true”</em></strong>&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span><span> </span>&lt;key column=&#8221; country_id&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;one-to-many class=&#8221; try.hibernate.example.model.City&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/set&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">The most recommended fetching strategy for collections is <strong><em>lazy=”true”</em></strong> This option is almost always used for collection mappings (it should be the default, and we recommend that you consider it as a default for all your collection mappings).</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;"><strong>One-to-One</strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;line-height:normal;">
<p class="MsoNoSpacing" style="text-align:justify;"><strong>Let’s start from a scenario; </strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><em>A company needs to record his client information; its home address and his/her company information with complete address for its processing. </em></p>
<p class="MsoNoSpacing" style="text-align:justify;">In order to map this scenario three tables are required<em>;</em></p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>1.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->A table named address having its attributes.</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>2.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->A table named user having user specific attributes with a foreign key of address,</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>3.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->A table named company having company specific attributes with a foreign key of address.</p>
<p class="MsoNoSpacing" style="text-align:justify;">
<p class="MsoNoSpacing" style="text-align:justify;">So also we need three classes namely Address, User and Company</p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> Class User{</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private long id;<span> </span><span> </span>//identifier property (primary key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">…</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">…</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private Address address;<span> </span>//referenced object (foreign key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">// all the properties will have getter and setters as we define properties with private access specifier.</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">}</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">Class Company</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private long id;<span> </span><span> </span>//identifier property (primary key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">…</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">…</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private Address address;<span> </span>//referenced object (foreign key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">// all the properties will have getter and setters as we define properties with private access specifier.</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">}</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">Class Address{</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private long id;<span> </span>//identifier property (primary key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">…</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">…</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private User user;<span> </span>//referenced object (foreign key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">private Company company;<span> </span>//referenced object (foreign key in associated table)</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">// all the properties will have getter and setters as we define properties with private access specifier.</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">}</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span>In all above three classes I just omitted properties of each class except the primary key property and associated class object that will work based on foreign key.</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">The hbm documents are; </span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><strong><em><span style="font-size:10pt;">user.hbm.xml</span></em></strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;class name=&#8221; try.hibernate.example.model.User&#8221; table=&#8221;user&#8221; lazy=”true”&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;id name=&#8221;id&#8221; column=&#8221;id&#8221;&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;generator class=&#8221;native&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/id&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>…</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>…<span> </span></span></p>
<p class="MsoNoSpacing" style="text-align:justify;">I just omitted the mappings of User object properties with user table columns; assuming you know this from previous discussion.</p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">&lt;many-to-one name=&#8221;address&#8221; outer-join=&#8221;auto&#8221; unique=”true” cascade=&#8221;all&#8221;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221; try.hibernate.example.model.Address” /&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNoSpacing" style="text-align:justify;">Its old <strong><em>many-to-one</em></strong> mapping element with two changes;</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>1.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->an extra attribute <strong><em>unique=”true”. </em></strong><span> </span>This attribute just change the behavior of many-to-one mapping. Without unique attribute this mapping means many addresses will be linked with same user. But our purpose is to define the relation as one-to-one. So <em>unique</em> attribute in this mapping make this as <em>one-to-one</em> association between user and address. Only one address can belong to one user.</p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:-0.25in;"><!--[if !supportLists]--><span><span>2.<span style="font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->Cascade=”all” here I preferred to use cascade with <strong><em>all. </em></strong><span> </span>This means any operation (save/update/delete) on user object will affect the address as well. If user is being removed then its address should also be removed from the database.</p>
<p><span style="font-size:10pt;"> </span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/class&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;/hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><strong><em><span style="font-size:10pt;">company.hbm.xml</span></em></strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><strong><em><span style="font-size:10pt;"> </span></em></strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;class name=&#8221; try.hibernate.example.model.company&#8221; table=&#8221;company&#8221; lazy=”true”&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;id name=&#8221;id&#8221; column=&#8221;id&#8221;&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;generator class=&#8221;native&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/id&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>…</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>…<span> </span></span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span style="font-size:10pt;">&lt;many-to-one name=&#8221;address&#8221; outer-join=&#8221;auto&#8221; unique=”true” cascade=&#8221;all&#8221;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;">class=&#8221; try.hibernate.example.model.Address” /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNoSpacing" style="text-align:justify;text-indent:0.25in;">Same as discussed in user.hbm document.</p>
<p class="MsoNoSpacing" style="text-align:justify;text-indent:0.25in;">
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/class&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;/hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> </span><strong><em><span style="font-size:10pt;">address.hbm.xml</span></em></strong></p>
<p class="MsoNoSpacing" style="text-align:justify;"><strong><em><span style="font-size:10pt;"> </span></em></strong><span style="font-size:10pt;">&lt;hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;class name=&#8221; try.hibernate.example.model.Address&#8221; table=&#8221;address&#8221; lazy=”true”&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;id name=&#8221;id&#8221; column=&#8221;id&#8221;&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;generator class=&#8221;native&#8221; /&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>&lt;/id&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>…</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"><span> </span>…<span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;text-indent:0.25in;line-height:normal;"><span style="font-size:10pt;">&lt;one-to-one name=&#8221;user&#8221; class=”</span><span style="font-size:10pt;">try.hibernate.example.model.</span><span style="font-size:10pt;">User&#8221;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:0.25in;"><span style="font-size:10pt;">property-ref=&#8221;user&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.25in;text-align:justify;"><span>user (of type User) is the name of property of Address that corresponds to foreign key association. But instead of mapping this property with some column of Address table used another attribute <strong><em>property-ref=”user”</em></strong> is used<strong><em>. </em></strong><span> </span>This means there is no need to have a separate column in user table because more than one table is being linked to address table using <em>one-to-one</em> association.</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:justify;text-indent:0.25in;line-height:normal;"><span style="font-size:10pt;">&lt;one-to-one name=&#8221;company&#8221; class=”</span><span style="font-size:10pt;">try.hibernate.example.model.</span><span style="font-size:10pt;">Company&#8221;</span></p>
<p class="MsoNoSpacing" style="margin-left:0.5in;text-align:justify;text-indent:0.25in;"><span style="font-size:10pt;">property-ref=&#8221;company&#8221;/&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;text-indent:0.5in;"><span style="font-size:10pt;"> same as above.</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> <span> </span>&lt;/class&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;">&lt;/hibernate-mapping&gt;</span></p>
<p class="MsoNoSpacing" style="text-align:justify;"><span style="font-size:10pt;"> </span>Someone might get confused about the many-to-one associations in these two scenarios. But in both cases the <em>unique</em> attribute is the main difference that is present in address case only. <em>unique</em> with value <em>true </em>makes the relation <em>one-to-one</em>. so in case of City/Country association we defined a collection and in case of Address/User or Address/Company we defined single object.</p>
<p class="MsoNoSpacing" style="text-align:justify;">All the mappings we defined in this scenario are bidirectional. There are many ways to use these mappings and also can be modified according to the requirements. Means if you don’t want to access company/user from address then there is no need to define <em>one-to-one</em> mapping in Address hbm document. Only the <em>many-to-one</em> mapping defined in user/company with <em>unique=”true”</em> is enough to make the relationship <em>one-to-one</em>. But that would be unidirectional. One can only access address from its particular object (user/company).</p>
<p class="MsoNormal" style="text-align:justify;">This is an overview of hibernate mapping and a simplest cases were defined here. In order to get the complete understanding and in depth knowledge of how hibernate works and how mappings can improve the efficiency I would recommend to study <strong><em>Hibernate in Action by Christian Bauer &amp; Gavin King.</em></strong> It’s the best book written on hibernate.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jobexperiences.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jobexperiences.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jobexperiences.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jobexperiences.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jobexperiences.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jobexperiences.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jobexperiences.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jobexperiences.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jobexperiences.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jobexperiences.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jobexperiences.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jobexperiences.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jobexperiences.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jobexperiences.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jobexperiences.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jobexperiences.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jobexperiences.wordpress.com&amp;blog=2162164&amp;post=7&amp;subd=jobexperiences&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jobexperiences.wordpress.com/2008/05/20/hibernate-mapping-mystery/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0f5f18df16c3d376009285069831c33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Curious HARD</media:title>
		</media:content>
	</item>
		<item>
		<title>Why spring provides too many types of controllers???</title>
		<link>http://jobexperiences.wordpress.com/2007/12/14/why-spring-provides-too-many-types-of-controllers/</link>
		<comments>http://jobexperiences.wordpress.com/2007/12/14/why-spring-provides-too-many-types-of-controllers/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 13:35:39 +0000</pubDate>
		<dc:creator>curioushard</dc:creator>
				<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://jobexperiences.wordpress.com/2007/12/14/why-spring-provides-too-many-types-of-controllers/</guid>
		<description><![CDATA[While working on MVC architecture we need different type of functionalities at minimum cost. Spring made the life easier for the java programmers with multiple types of controllers (C part of MVC that manage all the MVC structure of an application). The books available for the beginners of spring MVC provide the best theoretical description [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jobexperiences.wordpress.com&amp;blog=2162164&amp;post=3&amp;subd=jobexperiences&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">While working on MVC architecture we need different type of functionalities at minimum cost. Spring made the life easier for the java programmers with multiple types of controllers (C part of MVC that manage all the MVC structure of an application). </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The books available for the beginners of spring </span><span style="font-size:10pt;font-family:'Arial','sans-serif';">MVC</span><span style="font-size:10pt;font-family:'Arial','sans-serif';"> provide the best theoretical description of different types of controllers, how to use them etc&#8230; But most of the beginners get confused after reading so many types of controllers. The main question arise which controller should be used &amp; when? Can’t there be a pattern that provides us a better solution with some mixture of these? As some time we need only page navigation, some time we require form submission etc. </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The same problem I faced when I started working on spring MVC. But while working I succeeded to devise such a way of using ‘<i>MultiActionController’</i> with ‘<i>SimpleFormController’</i> enjoying their specific advantages while satisfying my requirements.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The purpose of this writing is just to give an idea while deciding which controller should be used for what purpose at the start of an enterprise application so that programmer can get the maximum benefits of spring MVC.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Normally <i>SimpleFormController</i> and <i>MultiActionController</i> are used to perform basic tasks in an enterprise application for related tasks to reduce the length of dispatcher-*.xml (dispatcher-servlet.xml). i would give the reader a very brief introduction of <i>SimpleFormController</i> &amp; <i>MultiActionController </i>in order to dive into the code example.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><b><span style="font-size:10pt;font-family:'Arial','sans-serif';"><font color="#800000">SimpleFormController</font></span></b></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><i><span style="font-size:10pt;font-family:'Arial','sans-serif';">SimpleFormController</span></i><span style="font-size:10pt;font-family:'Arial','sans-serif';"> is very useful in case where you want to send lots of inputs from a form to persist, i.e., if you are required to perform a task that requires lets say 20 to 30 inputs of different types from the user and submit this form for your own business logic and persistence for latter retrieval.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">In traditional jsp and servlet way </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">You will create a form using html having a all required inputs with a servlet mapped as its action </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Take inputs from the users and submit to a servlet </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Then it will use the <i>HttpServletRequest</i> to get all the parameters for further processing</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">It’s a hectic job to get all 20 or 30 fields putting them in a collection (although we can use beans in traditional jsps) or an object like BO and then perform the actual task on this data.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">But in case of spring’s <i>SimpleFormController</i> this whole process becomes very short as you only need to map a class to the jsp and this will be available to you will the inputs in the controller. It eliminates the hectic job of using <i>HttpServlerRequest</i> and fetching all the parameters one by one.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><b><span style="font-size:10pt;font-family:'Arial','sans-serif';"><font color="#800000">MultiActionController</font></span></b></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">If you want to perform some related tasks like manipulation of client entity, i.e., you want to add client’s info into the system, modify existing client, or want to view all the existing clients, then <i>MultiActionController</i><b> </b>would be the better choice as you requires almost same functionality with a little bit difference. So instead of rewriting the same code for the same functionality just showing the page (one for addClient, one for modifyClient, and one for viewClient) create a class having multiactioncontrolller functionality and display all these three pages using a single controller.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">It lessens your dispatcher entries; make all the functionality starting at the same point. After some time if you need to review this processes you shouldn’t need to search out how many controllers did you developed.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">MyMultiActionCntrl.java</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public class MyMultiActionCntrl extends MultiActionController{</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public ModelAndView clientIntro(HttpServletRequest request, </span></p>
<p class="MsoNormal" style="margin-left:0.25in;text-indent:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">HttpServletResponse response) throws Exception{</span></p>
<p class="MsoNormal" style="margin-left:0.25in;text-indent:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"> </span></p>
<p class="MsoNormal" style="margin-left:0.25in;text-indent:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">// such page can be used to give some simple description for this module</span></p>
<p class="MsoNormal" style="margin-left:0.25in;text-indent:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">return new ModeAndView(“clientIntro”);</span></p>
<p class="MsoNormal" style="text-indent:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">}</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"> </span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public ModelAndView addClient(HttpServletRequest request, </span></p>
<p class="MsoNormal" style="margin-left:0.25in;text-indent:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">HttpServletResponse response) throws Exception{</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>      </span>    return new ModeAndView(“addClient”);</span></p>
<p class="MsoNormal" style="text-indent:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">}</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public ModelAndView modifyClient(HttpServletRequest request,</span></p>
<p class="MsoNormal" style="margin-left:0.25in;text-indent:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span> </span>HttpServletResponse response) throws Exception{</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>      </span>    return new ModeAndView(“modifyClient”);</span></p>
<p class="MsoNormal" style="text-indent:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">}</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public ModelAndView viewClient(HttpServletRequest request,</span></p>
<p class="MsoNormal" style="margin-left:0.25in;text-indent:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span> </span>HttpServletResponse response) throws Exception{</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>      </span>    Map map = new HasgMap();</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>      </span>    map.put(“clients”,call a service layer function that returns the list of clients);</span></p>
<p class="MsoNormal" style="margin-left:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>      </span>    return new ModeAndView(“viewClient”);</span></p>
<p class="MsoNormal" style="text-indent:0.25in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">}</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">}</span></p>
<p class="MsoNormal" style="line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">This class may have as many functions as you require for different pages to be loaded.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">This workable url whould look like this </span></p>
<p class="MsoNormal" style="text-align:center;line-height:normal;" align="center"><i><span style="font-size:10pt;font-family:'Arial','sans-serif';">./myMAController.htm?action=”addClient”</span></i></p>
<p class="MsoNormal" style="text-align:center;line-height:normal;" align="center">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Mappings required for this class</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">1. &lt;bean id=&#8221;urlMapping&#8221; class=&#8221;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&#8221;&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>        </span>    &lt;property name=&#8221;mappings&#8221;&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>            </span>        &lt;props&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>                </span>            &lt;prop key=&#8221;/myMAController.htm&#8221;&gt;myMACntrl&lt;/prop&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>                        </span>        &lt;/prop&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>            </span>    &lt;/property&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">    &lt;/bean&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">1 a. <i>SimpleUrlHandlerMapping (above declared bean mapping)</i> provides the way to match the requested url part with one of its entries as in our case ‘./myMAController.htm?action=”addClient”’. with this given url myMACntrl is searched. That leads us to step 2.</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><br />
2. &lt;bean id=&#8221;myMACntrl&#8221; class=&#8221;com.domain.controller.MyMultiActionCntrl&#8221;&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>        </span>        &lt;property name=&#8221;methodNameResolver&#8221; ref=”nameResorlver&#8221;/&gt; </span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">    &lt;/bean&gt;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">2 A) ./myCntrl.htm that is searched and then mapped its value to a bean having the same id as in this case <i>myMACntrl</i>. – That is the class that have multiple functions to be called</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">2 B) this bean has property named <i>mathodNamerResolver</i> with reference to <i>nameResolver </i>bean<i> </i>which will resolve the method name</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">3. &lt;bean id=&#8221; nameResolver&#8221; class=&#8221;org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver&#8221;&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>        </span>        &lt;property name=&#8221;paramName&#8221;&gt;<span> </span>&lt;value&gt;action&lt;/value&gt;<span> </span>&lt;/property&gt;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">    &lt;/bean&gt;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">3 a) <i>nameResolver</i> <span> </span>bean have class <i>org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver</i> provided by spring that resolve the url. My method name as its name depicts with property <i>paramName</i> having value <i>action </i>(it can be any valid identifier to be used as name for method name to be resolved). </span></p>
<p class="MsoNormal" style="line-height:normal;"><i><span style="font-size:10pt;font-family:'Arial','sans-serif';">action </span></i><span style="font-size:10pt;font-family:'Arial','sans-serif';">will be the name given to the parameter that will have function name as value.</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"> </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Its means using this controller you don’t need to have separate controller for each page. Only you need is to mention the function name that will load the specific page.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span> </span>When we need to call one of these pages say ‘addClient’, we use the mapping as <i>‘./myMAContoller.htm?action=”addClient’</i>, and the spring will map it to the bean declared with id <i>myMACntrl</i> using the prop attribute.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span> </span>&lt;prop name=”./myMAController.htm”&gt;myMACntrl&lt;/prop&gt;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span> </span>Then the bean with id <i>myMAController</i> is searched which is the <i>MultiActionController</i> so the method with name ‘addClient’ will be searched that will load the page given as the returned ModelAndView of this method.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span> </span>return new ModeAndView(“addClient”)); </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The jsp page that will be loaded </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">addClient.jsp page</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"> </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">// just ignore the jstl usage for adding new client, will be discussed shortly for the case of HOW TO REUSE A PAGE </span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;html&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;title&gt;My First Spring App. &lt;/title&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;head&gt;&lt;/head&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;body&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;form id=’myClientForm’ method=’post’ action=’clientFormCntrl.htm’&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;c:set var=’client’ value=’${requestScope.referenceData.clientVO}’ scope=’page’/&gt;</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;input type=’text’ name=’name’ <span> </span>value=’${client.name}’/&gt;</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>            </span>&lt;input type=’text’ name=’address’ value=’${client.address}’/&gt;</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>            </span>&lt;input type=’text’ name=’category’ value=’${client.category}’/&gt;</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;input type=’submit’ value=’submit’ /&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;/form&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;/body&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;/html&gt;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">After loading this page we may use the <i>SimpleFormController</i> for form submission that would be better having a <i>commandClass</i> for true use of SFC. </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<address><b><i><span style="font-size:10pt;font-family:'Arial','sans-serif';">What is commandClass ???</span></i></b></address>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The class that is used to map with jsp form is called <i>commandClass</i> in terms of spring. While submitting a form to <i>SimpleFormController</i> it’s of ‘Object’ Type that is required to cast into the specific type. As in our case we use a class <i>ClientVO</i> as <i>commandClass</i> <span> </span>and <i>onSubmit</i> function of <i>SimpleFormController</i> as of Object type. Then it’s required to cast into its actual type that’s <i>ClientVO</i>.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public class ClientVO{</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>            </span>    // property name must match with the ‘name’ attributes of each input tag to be mapped with command class</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>            </span>    private String name=””;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>            </span>    private String address=””;</span></p>
<p><span style="font-size:10pt;font-family:'Arial','sans-serif';">private String category=””;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">    // getters &amp; setters</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">    // these wrapper functions must be there in order to map all the fields of jsp</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">}</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">And the controller class will look like this</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public class MyClientFormCntrl extends SimpleFormContorller{</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">        Object command, BindException exception ) throws Exception{</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">            ClientVO clientVO = (ClientVO)command;</span></p>
<p class="MsoNormal" style="margin-left:0.5in;text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">// this clientVO will have all the fields input from the page you may use it for validation or business logic and may convert in to an actual BO for persistence. </span></p>
<p class="MsoNormal" style="margin-left:0.5in;text-align:justify;line-height:normal;"><i><span style="font-size:10pt;font-family:'Arial','sans-serif';">One thing more, all these should be done in separate service layer so that your controller only control your application flow and all other work should be separate from this.</span></i></p>
<p class="MsoNormal" style="margin-left:0.5in;text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Upon success of you process whatever you want to do </span></p>
<p class="MsoNormal" style="margin-left:0.5in;text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">return new ModelAndView(getSuccessView());</span></p>
<p class="MsoNormal" style="margin-left:0.5in;text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">else<span>  </span>// in case of any problem </span></p>
<p class="MsoNormal" style="margin-left:0.5in;text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">return new ModelAndView (getErrorPage());</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">}</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">And the mappings required for the controller are</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>    </span>&lt;bean id=&#8221;myClientSFCntrl&#8221; class=&#8221;com.domain.controller.MyClientFormCntrl&#8221;&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>    </span>        &lt;property name=&#8221;commandClass&#8221; value=&#8221;com.domain.model.ClientVO&#8221;/&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>        </span>        &lt;property name=&#8221;successView&#8221; value=&#8221;clientIntro&#8221;/&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>    </span>&lt;/bean&gt; </span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">// successView can be any page with having result of last page. I reused the same intro page as successView also. In such case you may set a msg string into the session that can be displayed on the intro page like what I did </span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">return new ModelAndView(getSuccessView(),”resultMsg”,”Client’s record has been added successfully”); </span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">In this case I reused the page for two purposes as there is no need to create a separate page just for message display.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Up to this level we can load a page <i>addClient</i> using <i>multiactioncontroller</i> and submit form using <i>simpleFormController</i>. </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The task of modifying an existing client can also be done without creating any other page and controller, using the same <i>addClient</i> page and same <i>SimpleFormController</i>. The modifications required are as follows;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">HOW TO REUSE THE <i>addClient</i> page for modify client as we need to display the existing client’s record, make available for changes and then submit to save the changes.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">1. Modify the <i>modifyClient</i> function’s body of <i>MultiActionClass</i> class as;</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">public ModelAndView modifyClient(HttpServletRequest request, HttpServletResponse response) throws Exception{</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">// search the required client’s record and populate the ClientVO object that is mapped with our ‘addClient’ page.</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">ClientVO client = service.getClientVO(searching criteria);</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">// say service is a client that helps searching client as populate VO object.</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Map map = new HashMap();</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">map.put(“clientVO”,client);</span></p>
<p class="MsoNormal" style="margin-left:0.5in;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>            </span>return new ModeAndView(“addClient”,”referenceData”, map);</span></p>
<p class="MsoNormal" style="line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">}</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Using the same mapping <i>./myMAController.htm?action=”modifyClient”</i> when <i>modifyClient</i> function is called it will load the <i>clientVO</i> that will be available at the jsp page</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">And the jstl used at <i>addClient</i> page do all to display the client’s info in the specified fields. That’s why we used the jstl tags to fetch the reference data having clientVO. Jstl will be discussed under the head of ‘<i>Jstl lessens the work of programmer that jsp tags</i>’</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">2. The change in ClientVO is the addition of clientId as property</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">private String clientId=””;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span> </span>to hold the id of fetched client. So that we can use the same id for updating of fetched client record otherwise underlying hibernate layer will add a new record instead of updating the previous one.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">3. Add a hidden input type field in the ’<i>addClient.jsp’</i> to hold the ‘id’ as</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">&lt;input type=’hidden’ name=’clientId’ value=’${client.clientId}’ /&gt;</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Inside the form tag.</span></p>
<p class="MsoNormal" style="margin-left:0;text-align:justify;text-indent:0;line-height:normal;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:'Arial','sans-serif';"><span>1.<span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;">             </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:'Arial','sans-serif';">You need to check the id of the <i>clientVO</i> whether its value is ’0’ or greater than ‘0’. If its having value equal to ‘0’ this means that new client is going to be inserted into the record otherwise <i>clientId</i> has the value of updating client’s id. So the existing record is going to be updated. </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The best place for such type of checks can be your service class that has functionalities like fetching client’s record and populating <i>clientVO</i> object accordingly and also vice versa in case of insertion into the database that will require conversion from <i>clientVO</i> to actual business Object say Client.<span>  </span></span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">Up till now using My<i>MultiActionCntrl</i> that’s <i>MultiActionController</i> and <i>MyClientFormCntrl</i> that’s <i>SimpleFormController</i> we can add a new client’s record into our System and modify an existing client’s record. </span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The same way we can combine our similar tasks under <i>MultiActionController </i>and can use the <i>SimpleFormController</i> for relatively same tasks.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">This is the way I devised a way to perform my tasks during job while catering the best use of spring controllers I could.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">There are some other functions in <i>SimpleFormController</i> like <i>onSubmit</i> that can also be used as well. But the user should first understand their best usage scenario.</span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;"><span style="font-size:10pt;font-family:'Arial','sans-serif';">The reader may find many other alternative functions for form submission under <i>SimpleFormController </i>having different signatures. So the reader may use such alternatives also as for his/her convenience. In the same way <i>MultiActionController </i>also has another way to perform the same task like <i>ProportyMethodNameResolver. </i></span></p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<p class="MsoNormal" style="text-align:justify;line-height:normal;">&nbsp;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jobexperiences.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jobexperiences.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jobexperiences.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jobexperiences.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jobexperiences.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jobexperiences.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jobexperiences.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jobexperiences.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jobexperiences.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jobexperiences.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jobexperiences.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jobexperiences.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jobexperiences.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jobexperiences.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jobexperiences.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jobexperiences.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jobexperiences.wordpress.com&amp;blog=2162164&amp;post=3&amp;subd=jobexperiences&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jobexperiences.wordpress.com/2007/12/14/why-spring-provides-too-many-types-of-controllers/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0f5f18df16c3d376009285069831c33?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Curious HARD</media:title>
		</media:content>
	</item>
	</channel>
</rss>
