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

<channel>
	<title>Articles</title>
	<atom:link href="http://dev.nirmalya.net/articles/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.nirmalya.net/articles</link>
	<description>Random articles  to help others who might be facing similar situations/problems (previously faced by me) during development.</description>
	<lastBuildDate>Wed, 22 Feb 2012 08:23:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Installing Tomcat 7 On Ubuntu And Accessing It Remotely</title>
		<link>http://dev.nirmalya.net/articles/setup/tomcat-7-ubuntu-remote-access</link>
		<comments>http://dev.nirmalya.net/articles/setup/tomcat-7-ubuntu-remote-access#comments</comments>
		<pubDate>Wed, 22 Feb 2012 07:23:24 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Setup]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=364</guid>
		<description><![CDATA[I installed Tomcat 7.0.26 on a standard.xsmall instance with a Ubuntu 11.04 image following some pretty good instructions on Diego Benna&#8217;s blog. After updating the required configuration files, I was able to access the server locally, but unable to access remotely. For future reference, listed below are steps I followed to resolve it. Installing Java [...]]]></description>
			<content:encoded><![CDATA[<p>I installed Tomcat 7.0.26 on a <a href="http://www.hpcloud.com/products/cloud-compute" target="_blank">standard.xsmall instance</a> with a Ubuntu 11.04 image following some <a href="http://diegobenna.blogspot.com/2011/01/install-tomcat-7-in-ubuntu-1010.html" target="_blank">pretty good instructions on Diego Benna&#8217;s blog</a>. After updating the required configuration files, I was able to access the server locally, but unable to access remotely. For future reference, listed below are steps I followed to resolve it.<br />
<span id="more-364"></span><br />
<big><strong>Installing Java 7</strong></big><br />
Please refer to the excellent instructions at <a href="http://brunoreis.com/tech/intalling-java-ubuntu-natty/" target="_blank">http://brunoreis.com/tech/intalling-java-ubuntu-natty/</a>.</p>
<p><big><strong>Installing Tomcat 7.0.26</strong></big><br />
Preparation</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf apache-tomcat-7.0.26.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> apache-tomcat-7.0.26<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>tomcat7</pre></div></div>

<p>Next, edit <code>/etc/environment</code>. Contents of this file</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">JAVA_HOME</span>=<span style="color: #ff0000;">&quot;/usr/lib/jvm/java-7-sun/&quot;</span>
<span style="color: #007800;">JRE_HOME</span>=<span style="color: #ff0000;">&quot;/usr/lib/jvm/java-7-sun/jre&quot;</span>
<span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;/usr/local/sbin:/usr/games:<span style="color: #007800;">$JAVA_HOME</span>:<span style="color: #007800;">$JRE_HOME</span>&quot;</span></pre></div></div>

<p>Next, edit <code>/usr/share/tomcat7/bin/catalina.sh</code>. Add in these 2 lines just after the <code>#!/bin/sh</code></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">JAVA_HOME</span>=<span style="color: #ff0000;">&quot;/usr/lib/jvm/java-7-sun/&quot;</span>
<span style="color: #007800;">JRE_HOME</span>=<span style="color: #ff0000;">&quot;/usr/lib/jvm/java-7-sun/jre&quot;</span></pre></div></div>

<p>Next, edit <code>/usr/share/tomcat7/conf/tomcat-users.xml</code>.<br />
Add the following just before the end of the <code>tomcat-users</code> element.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;yourAdminUsername&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;yourAdminPassword&quot;</span></span>
<span style="color: #009900;"> <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;manager-gui,admin-gui,manager,admin,manager-script,admin-script&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p><big><strong>Starting up Tomcat</strong></big></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>tomcat7<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>startup.sh</pre></div></div>

<p>Since I do not have local access to my instance, I used wget to check the local access.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">8080</span></pre></div></div>

<p>The contents are written to <code>index.html</code>. You can then try to <code>wget http://your-instance-public-ip:8080</code>, but most likely it will not work at this point.</p>
<p><big><strong>Configuring The Firewall</strong></big><br />
Please refer to the excellent instructions at <a href="http://chiralsoftware.com/linux-system-administration/ubuntu-firewall-iptables.seam" target="_blank">http://chiralsoftware.com/linux-system-administration/ubuntu-firewall-iptables.seam</a>. Summarized below</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #000000;">1</span> <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-j</span> ACCEPT
$ iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
$ iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
$ iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
$ iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-j</span> DROP
$ iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> REDIRECT <span style="color: #660033;">--to-port</span> <span style="color: #000000;">8080</span>
$ iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #000000;">3</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">8080</span> <span style="color: #660033;">-j</span> ACCEPT
$ iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-o</span> lo <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> REDIRECT <span style="color: #660033;">--to-port</span> <span style="color: #000000;">8080</span>
$ iptables-save <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>iptables.rules</pre></div></div>

<p>Next, reboot your instance, restart Tomcat and you should now be able to access http://your-instance-public-ip</p>
<p>Hope this helps.</p>
<p><big><strong>References</strong></big></p>
<ul>
<li><a href="http://brunoreis.com/tech/intalling-java-ubuntu-natty/" target="_blank">http://brunoreis.com/tech/intalling-java-ubuntu-natty/</a></li>
<li><a href="http://diegobenna.blogspot.com/2011/01/install-tomcat-7-in-ubuntu-1010.html" target="_blank">http://diegobenna.blogspot.com/2011/01/install-tomcat-7-in-ubuntu-1010.html</a></li>
<li><a href="http://chiralsoftware.com/linux-system-administration/ubuntu-firewall-iptables.seam" target="_blank">http://chiralsoftware.com/linux-system-administration/ubuntu-firewall-iptables.seam</a></li>
<li><a href="http://learnedstuffs.wordpress.com/2011/07/16/enabling-remote-access-on-apache-tomcat/" target="_blank">http://learnedstuffs.wordpress.com/2011/07/16/enabling-remote-access-on-apache-tomcat/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/setup/tomcat-7-ubuntu-remote-access/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SimpleJPA + Maven + Dependencies</title>
		<link>http://dev.nirmalya.net/articles/java/simplejpa-maven-dependencies</link>
		<comments>http://dev.nirmalya.net/articles/java/simplejpa-maven-dependencies#comments</comments>
		<pubDate>Sun, 01 Jan 2012 19:44:28 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Setup]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[SimpleDB]]></category>
		<category><![CDATA[SimpleJPA]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=342</guid>
		<description><![CDATA[Whilst I am very grateful to the folks who developed SimpleJPA, I found it a bit problematic building (with Maven) a project having SimpleJPA as of its dependencies. In this article, I attempt to make it easier for others who intend to use Maven for building their project which uses SimpleJPA. The Need To Add SimpleJPA To [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst I am very grateful to the folks who developed <a href="http://code.google.com/p/simplejpa/" target="_blank">SimpleJPA</a>, I found it a bit problematic building (with <a href="http://maven.apache.org/" target="_blank">Maven</a>) a project having SimpleJPA as of its dependencies. In this article, I attempt to make it easier for others who intend to use Maven for building their project which uses SimpleJPA.</p>
<p><span id="more-342"></span><br />
<big><strong>The Need To Add SimpleJPA To Maven Local Repository</strong></big><br />
To begin with, (as of now) one cannot just add in a dependency similar to the one below and expect the build to proceed smoothly.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.spaceprogram<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>simplejpa<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>I had to download the SimpleJPA JAR file and it to my maven local repository. To do so, you may use the command,</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">mvn install:install-file
 -Dfile=PathToJARFile\simplejpa-1.5.jar
 -DgroupId=com.spaceprogram
 -DartifactId=simplejpa -Dversion=1.5 -Dpackaging=jar -DgeneratePom=true</pre></div></div>

<p><big><strong>The Need To Manually Manage SimpleJPA&#8217;s Dependencies</strong></big><br />
SimpleJPA&#8217;s<a href="http://code.google.com/p/simplejpa/wiki/GettingStarted" target="_blank">GettingStarted</a> Wiki page lists its dependencies. Since I couldn&#8217;t find a working Maven <code>pom.xml</code> for SimpleJPA, I created one and pasted below is the <code>dependencies</code> section which you can just copy into your project&#8217;s <code>pom.xml</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>cglib<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>cglib-nodep<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.2.2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.amazonaws<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>aws-java-sdk<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0.002<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.spaceprogram<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>kitty-cache<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-codec<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-codec<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-collections<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-collections<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3.2.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-lang<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-lang<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-logging<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-logging<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.1.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>junit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>junit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3.8.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>test<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>net.sf.ehcache<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ehcache-core<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.5.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>net.sf.scannotation<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>scannotation<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0.2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.httpcomponents<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>httpclient<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4.1.2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.hibernate<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ejb3-persistence<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0.2.GA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.javassist<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javassist<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3.15.0-GA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- SimpleJPA --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.spaceprogram<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>simplejpa<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Please take note</p>
<ul>
<li>GroupIds, ArtifcatIds, versions determined using <a href="http://search.maven.org/#search" target="_blank">http://search.maven.org/#search</a></li>
<li>You will also need to download <span style="color: #3366ff;"><strong><code>ejb3-persistence-1.0.2.GA.jar</code></strong></span> from <a href="http://mirrors.ibiblio.org/pub/mirrors/maven2/org/hibernate/ejb3-persistence/1.0.2.GA/" target="_blank">here</a> and add to maven local repository using the command

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">mvn install:install-file
 -Dfile=PathToJARFile\ejb3-persistence-1.0.2.GA.jar
 -DgroupId=org.hibernate
 -DartifactId=ejb3-persistence
 -Dversion=1.0.2.GA -Dpackaging=jar
 -DgeneratePom=false</pre></div></div>

</li>
<li>You will also need to download <span style="color: #3366ff;"><strong><code>KittyCache-1.2.jar</code></strong></span> from <a href="http://code.google.com/p/kitty-cache/downloads/list" target="_blank">here</a> and add to maven local repository using the command

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">mvn install:install-file
 -Dfile=PathToJARFile\KittyCache-1.2.jar
 -DgroupId=com.spaceprogram
 -DartifactId=kitty-cache
 -Dversion=1.2 -Dpackaging=jar -DgeneratePom=true</pre></div></div>

</li>
</ul>
<p><big><strong>References:</strong></big></p>
<ul>
<li><a title="Add a jar to maven local repository, link opens in a new tab or window" href="http://wrongdoor.wordpress.com/2010/11/28/add-a-jar-to-maven-local-repository/" target="_blank">http://wrongdoor.wordpress.com/2010/11/28/add-a-jar-to-maven-local-repository/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/java/simplejpa-maven-dependencies/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regex Pattern In XSD For Comma-Separated Attribute Value</title>
		<link>http://dev.nirmalya.net/articles/uncategorized/regex-pattern-in-xsd-for-comma-separated-attribute-value</link>
		<comments>http://dev.nirmalya.net/articles/uncategorized/regex-pattern-in-xsd-for-comma-separated-attribute-value#comments</comments>
		<pubDate>Wed, 16 Jun 2010 07:40:14 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[xsd]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=338</guid>
		<description><![CDATA[Relevant Section Of The XML &#60;my_element xyz=&#34;ABC3&#34;/&#62; &#60;my_element xyz=&#34;ABC21,a1&#34;/&#62; Relevant Section Of The XSD 1 2 3 4 5 6 7 8 9 10 11 &#60;xs:element name=&#34;my_element&#34; maxOccurs=&#34;unbounded&#34; minOccurs=&#34;1&#34;&#62; &#60;xs:complexType&#62; &#60;xs:attribute name=&#34;xyz&#34; use=&#34;required&#34;&#62; &#60;xs:simpleType&#62; &#60;xs:restriction base=&#34;xs:string&#34;&#62; &#60;xs:pattern value=&#34;[a-zA-Z0-9]+[,a-zA-Z0-9]*&#34;/&#62; &#60;/xs:restriction&#62; &#60;/xs:simpleType&#62; &#60;/xs:attribute&#62; &#60;/xs:complexType&#62; &#60;/xs:element&#62;]]></description>
			<content:encoded><![CDATA[<p><strong>Relevant Section Of The XML</strong></p>

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


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

<p><strong>Relevant Section Of The XSD</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;my_element&quot;</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">&quot;unbounded&quot;</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;xyz&quot;</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;required&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:simpleType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:restriction</span> <span style="color: #000066;">base</span>=<span style="color: #ff0000;">&quot;xs:string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:pattern</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;[a-zA-Z0-9]+[,a-zA-Z0-9]*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:restriction<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:simpleType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/uncategorized/regex-pattern-in-xsd-for-comma-separated-attribute-value/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chaining 2 jQuery UI Datepickers</title>
		<link>http://dev.nirmalya.net/articles/javascript/chaining-2-jquery-ui-datepickers</link>
		<comments>http://dev.nirmalya.net/articles/javascript/chaining-2-jquery-ui-datepickers#comments</comments>
		<pubDate>Thu, 10 Jun 2010 07:49:51 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=331</guid>
		<description><![CDATA[A simple example to chain 2 jQuery UI datepickers such that when a date is selected in the first datepicker (a.k.a. the &#8216;from date&#8216;, date1), the minimum date in the second datepicker (a.k.a. the &#8216;to date&#8216;, date2) is set accordingly. Similarly it handles the case where the &#8216;to date&#8216; is selected before the &#8216;from date&#8216;, [...]]]></description>
			<content:encoded><![CDATA[<p>A simple example to chain 2 jQuery UI datepickers such that when a date is selected in the first datepicker (a.k.a. the &#8216;<i>from date</i>&#8216;, <code>date1</code>), the minimum date in the second datepicker (a.k.a. the &#8216;<i>to date</i>&#8216;, <code>date2</code>) is set accordingly. Similarly it handles the case where the &#8216;<i>to date</i>&#8216; is selected before the &#8216;<i>from date</i>&#8216;, in which case the maximum date in the &#8216;<i>from date</i>&#8216; is lesser than the &#8216;<i>to date</i>&#8216; but before current date. </p>
<p><strong>Relevant HTML For Datepicker Placeholders</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;date1&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;date1&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;date2&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;date2&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span></pre></div></div>

<p><strong>Relevant jQuery Setup Code</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
  $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#date1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      autoSize<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
      constrainInput<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
      dateFormat<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ddMyy'</span><span style="color: #339933;">,</span> 
      minDate<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> 
      maxDate<span style="color: #339933;">:</span> <span style="color: #3366CC;">'+90D'</span><span style="color: #339933;">,</span> 
      onSelect<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>dateText<span style="color: #339933;">,</span> inst<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#date2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepicker</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;minDate&quot;</span><span style="color: #339933;">,</span>dateText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#date2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      autoSize<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
      constrainInput<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
      dateFormat<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ddMyy'</span><span style="color: #339933;">,</span> 
      minDate<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> 
      maxDate<span style="color: #339933;">:</span> <span style="color: #3366CC;">'+90D'</span><span style="color: #339933;">,</span> 
      onSelect<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>dateText<span style="color: #339933;">,</span> inst<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#date1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepicker</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;maxDate&quot;</span><span style="color: #339933;">,</span>dateText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//Other setup</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>In the jQuery setup code above, I have also set the following</p>
<ul>
<li>Do not allow selection of dates before current date (<code>minDate: 0</code>)</li>
<li>Do not allow selection of dates 90 days after current date (<code>maxDate: '+90D'</code>)</li>
<li>Date format similar to &#8216;<i>17Jun2010</i>&#8216;</li>
<li>The &#8216;<code>constrainInput: true</code>&#8216; indicates that the input field is constrained to those characters allowed by the current dateFormat.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/javascript/chaining-2-jquery-ui-datepickers/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Spring + JPA + Hibernate + Tomcat + EHCache</title>
		<link>http://dev.nirmalya.net/articles/java/spring-jpa-hibernate-tomcat-ehcache</link>
		<comments>http://dev.nirmalya.net/articles/java/spring-jpa-hibernate-tomcat-ehcache#comments</comments>
		<pubDate>Sat, 01 May 2010 17:27:09 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[EHCache]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=305</guid>
		<description><![CDATA[Having @ManyToMany(fetch=FetchType.EAGER) attributes can slow down retrieval quite significantly (up to 40 times slower). I recall reading somewhere that FetchType.EAGER is the default for @ManyToMany associations. Also, from experience I noticed that setting FetchType.LAZY caused a org.hibernate.LazyInitializationException thrown with exception message similar to, failed to lazily initialize a collection of role: com.xyz.domain.EntityOne.images, no session or session [...]]]></description>
			<content:encoded><![CDATA[<p>Having <code>@ManyToMany(fetch=FetchType.EAGER)</code> attributes can slow down retrieval quite significantly (up to 40 times slower).</p>
<p>I recall reading somewhere that <code>FetchType.EAGER</code> is the default for <code>@ManyToMany</code> associations. Also, from experience I noticed that setting <code>FetchType.LAZY</code> caused a <code>org.hibernate.LazyInitializationException</code> thrown with exception message similar to, <code><span style="color: #ff0000;">failed to lazily initialize a collection of role</span>: com.xyz.domain.EntityOne.images, <span style="color: #ff0000;">no session or session was closed</span></code>.</p>
<p>So, it seemed that the only other way to quickly reduce the time it took (for the retrieval) was to look into the caching options such as query caching, second-level caching, both of which are supported by Hibernate (the webapp&#8217;s JPA provider). For more information on second-level caching, please refer to <a href="http://www.javalobby.org/java/forums/t48846.html" target="_blank" title="Opens in a new window or tab">this article</a>.</p>
<p>Integrating Spring + JPA + Hibernate + Tomcat + EHCache took me a few hours this afternoon, but the effort paid off. The retrieval is now 40 times faster!</p>
<p>This post is summarizing the setup involved in getting them all to work together.</p>
<p><strong>Relevant Section Of <code>persistence.xml</code>:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;provider<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.hibernate.ejb.HibernatePersistence<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/provider<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shared-cache-mode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ENABLE_SELECTIVE<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shared-cache-mode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.cache.provider_class&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.hibernate.cache.SingletonEhCacheProvider&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.cache.provider_configuration&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/ehcache.xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.cache.use_second_level_cache&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.cache.use_query_cache&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Notes:</p>
<ul>
<li>The <code>persistence.xml</code> is located at <code>{tomcat}/webapps/{your-webapp}/META-INF</code>.</li>
<li>I used <code>org.hibernate.cache.SingletonEhCacheProvider</code> instead of <code>org.hibernate.cache.EhCacheProvider</code>. I was getting a WARN message if I used <code>org.hibernate.cache.EhCacheProvider</code>. I referred to <a href="http://blog.cherouvim.com/singleton-ehcache-cachemanager-warning-fix/" target="_blank" title="Opens in a new window or tab">this post</a> for a fix.</li>
</ul>
<p><strong>Relevant Section Of <code>ehcache.xml</code>:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;diskStore</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;user.dir/mywebapp-special-cache-folder&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;defaultCache</span> <span style="color: #000066;">eternal</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">overflowToDisk</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">maxElementsInMemory</span>=<span style="color: #ff0000;">&quot;1000&quot;</span> <span style="color: #000066;">timeToIdleSeconds</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">timeToLiveSeconds</span>=<span style="color: #ff0000;">&quot;60&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.xyz.domain.EntityTwo&quot;</span> <span style="color: #000066;">eternal</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">overflowToDisk</span>=<span style="color: #ff0000;">&quot;true&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">maxElementsInMemory</span>=<span style="color: #ff0000;">&quot;1000&quot;</span> <span style="color: #000066;">timeToIdleSeconds</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">timeToLiveSeconds</span>=<span style="color: #ff0000;">&quot;600&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">diskPersistent</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">diskExpiryThreadIntervalSeconds</span>=<span style="color: #ff0000;">&quot;300&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.xyz.domain.EntityOne&quot;</span> <span style="color: #000066;">eternal</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">overflowToDisk</span>=<span style="color: #ff0000;">&quot;true&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">maxElementsInMemory</span>=<span style="color: #ff0000;">&quot;1000&quot;</span> <span style="color: #000066;">timeToIdleSeconds</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">timeToLiveSeconds</span>=<span style="color: #ff0000;">&quot;600&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">diskPersistent</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">diskExpiryThreadIntervalSeconds</span>=<span style="color: #ff0000;">&quot;300&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.xyz.domain.EntityOne.images&quot;</span> <span style="color: #000066;">eternal</span>=<span style="color: #ff0000;">&quot;false&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">overflowToDisk</span>=<span style="color: #ff0000;">&quot;true&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">maxElementsInMemory</span>=<span style="color: #ff0000;">&quot;1000&quot;</span> <span style="color: #000066;">timeToIdleSeconds</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">timeToLiveSeconds</span>=<span style="color: #ff0000;">&quot;600&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">diskPersistent</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">diskExpiryThreadIntervalSeconds</span>=<span style="color: #ff0000;">&quot;300&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Notes:</p>
<ul>
<li>The <code>ehcache.xml</code> is located at <code>{tomcat}/webapps/{your-webapp}/WEB-INF/classes</code>.</li>
<li>The <code>diskStore</code> element indicates where the files to be used for caching will be stored for the entities I wish to be made persistent to disk. In my web application, the files are stored under <code>{tomcat}/bin/{mywebapp-special-cache-folder}</code></li>
<li><code>diskPersistent="true"</code> indicates that the disk store (for the specific entity) is persistent between cache and VM restarts. Please refer to the <a href="http://ehcache.org/documentation/storage_options.html" target="_blank" title="Opens in a new window or tab">EHCache documentation on disk storage</a> for more information.</li>
</ul>
<p><strong>Relevant JARs:</strong> under <code>{tomcat}/webapps/{your-webapp}/WEB-INF/lib</code></p>
<ul>
<li><code>ehcache-core-2.0.1.jar</code></li>
<li><code>hibernate3.jar</code></li>
<li><code>hibernate-jpa-2.0-api-1.0.0.Final.jar</code></li>
<li><code>slf4j-api-1.5.8.jar</code></li>
<li><code>slf4j-log4j12-1.5.6.jar</code></li>
<li>Spring 3.0.2 JARs..</li>
</ul>
<p><strong>Relevant Section Of Spring Configuration:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- there should be a way out of hardcoding the location of the properties file --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;location&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/spring-hes-db.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- ENTITY MANAGER FACTORY --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- LocalEntityManagerFactoryBean did not work for me --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;emf-p&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;persistenceUnitManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;pum&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;persistenceUnitName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;pu1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;dataSource-p&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jpaVendorAdapter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;database&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;MYSQL&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;showSql&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;generateDdl&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;databasePlatform&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.hibernate.dialect.MySQLDialect&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- TRANSACTION MANAGER --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;entityManagerFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;emf-p&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;dataSource-p&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- DATA SOURCES --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;dataSource-p&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://${db.host}:${db.port}/${db.name}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.username}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.password}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- JPA TEMPLATE --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jpaTemplate&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.JpaTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;entityManagerFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;emf-p&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- DAOs --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;entityOneDao&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;hes.db.impl.EntityOneDAOImpl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jpaTemplate&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;jpaTemplate&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- PERSISTENCE UNIT --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;pum&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;persistenceXmlLocations&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>META-INF/persistence.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSources&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;map<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;remoteDataSource&quot;</span> <span style="color: #000066;">value-ref</span>=<span style="color: #ff0000;">&quot;dataSource-p&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/map<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultDataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;dataSource-p&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Some of this may be redundant and will be cleaned up later.</p>
<p>If you have some better ideas, please do share. Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/java/spring-jpa-hibernate-tomcat-ehcache/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>AnnotationException : Entity X References An Unknown Entity Y</title>
		<link>http://dev.nirmalya.net/articles/java/annotationexception-entity-x-references-an-unknown-entity-y</link>
		<comments>http://dev.nirmalya.net/articles/java/annotationexception-entity-x-references-an-unknown-entity-y#comments</comments>
		<pubDate>Thu, 29 Apr 2010 18:33:43 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JPA]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=296</guid>
		<description><![CDATA[When the persistence provider complains about "unknown entity" when creating a one-to-one (or many-to-one) relationship between 2 entities, it helps to check the persistence.xml.]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> I was getting an org.hibernate.AnnotationException when creating a bidirectional one-to-one relationship between 2 entities (EntityOne and EntityTwo).</p>
<p><strong>Relevant Section Of StackTrace:</strong><br />
<code><strong>Caused by: </strong><strong><span style="color: #ff0000;">org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.xyz.domain.EntityOne.anImage references an unknown entity: com.xyz.domain.EntityTwo</span></strong><br />
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:103)<br />
at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:541)<br />
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:523)<br />
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:380)<br />
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)<br />
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1449)</code></p>
<p><strong>Relevant Section Of EntityOne&#8217;s Code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;entity1&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EntityOne <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
  @Id
  @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
  @Column<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;e1_id&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
&nbsp;
  @OneToOne<span style="color: #009900;">&#40;</span>fetch <span style="color: #339933;">=</span> FetchType.<span style="color: #006633;">LAZY</span>, optional <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
  @JoinTable<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;entity1_entity2_map&quot;</span>,
    joinColumns <span style="color: #339933;">=</span> @JoinColumn<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;e1_id&quot;</span><span style="color: #009900;">&#41;</span>,
    inverseJoinColumns <span style="color: #339933;">=</span> @JoinColumn<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;e2_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">private</span> EntityTwo anImage<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Other code</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Relevant Section Of EntityTwo&#8217;s Code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;entity2&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EntityTwo <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
  @Id
  @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
  @Column<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;e2_id&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
&nbsp;
  @OneToOne<span style="color: #009900;">&#40;</span>mappedBy <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;anImage&quot;</span>, optional <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">private</span> EntityOne e1<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Other code</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Solution That Worked For Me:</strong><br />
Check the <code>persistence.xml</code> to ensure that the 2 entities (EntityOne and EntityTwo) are listed. Previously I had not included EntityTwo, which is why I kept getting the message <em>com.xyz.domain.EntityOne.anImage references an unknown entity: com.xyz.domain.EntityTwo</em></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    com.xyz.domain.EntityOne
    com.xyz.domain.EntityTwo
    <span style="color: #808080; font-style: italic;">&lt;!-- other configurations --&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/java/annotationexception-entity-x-references-an-unknown-entity-y/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding/Removing Workspaces In Eclipse</title>
		<link>http://dev.nirmalya.net/articles/uncategorized/addingremoving-workspaces-in-eclipse</link>
		<comments>http://dev.nirmalya.net/articles/uncategorized/addingremoving-workspaces-in-eclipse#comments</comments>
		<pubDate>Wed, 24 Mar 2010 02:32:45 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Eclipse]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=286</guid>
		<description><![CDATA[Go to {path-to-Eclipse-installation}\configuration\.settings Open the file &#8220;org.eclipse.ui.ide.prefs&#8221; using any text editor Look out for the property &#8220;RECENT_WORKSPACES&#8221; which stores the paths to the workspaces currently in use, each separated by &#8216;\n&#8217; (for example, C\:\\eclipse-workspaces\\customer1\nC\:\\eclipse-workspaces\\customer2\nC\:\\eclipse-workspaces\\customer3\nC\:\\eclipse-workspaces\\customer4)for a setup similar to&#160;&#160;eclipse-workspaces&#160;&#160;&#160;&#160;- customer1&#160;&#160;&#160;&#160;- customer2&#160;&#160;&#160;&#160;- customer3&#160;&#160;&#160;&#160;- customer4 To add a workspace, add the full path (preceded by a &#8216;\n&#8217;) to [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Go to {<em>path-to-Eclipse-installation</em>}\configuration\.settings</li>
<li>Open the file &#8220;<code>org.eclipse.ui.ide.prefs</code>&#8221; using any text editor</li>
<li>Look out for the property &#8220;RECENT_WORKSPACES&#8221; which stores the paths to the workspaces currently in use, each separated by &#8216;\n&#8217; (for example, C\:\\eclipse-workspaces\\customer1\nC\:\\eclipse-workspaces\\customer2\nC\:\\eclipse-workspaces\\customer3\nC\:\\eclipse-workspaces\\customer4)<br />for a setup similar to<br /><code>&nbsp;&nbsp;eclipse-workspaces<br />&nbsp;&nbsp;&nbsp;&nbsp;- customer1<br />&nbsp;&nbsp;&nbsp;&nbsp;- customer2<br />&nbsp;&nbsp;&nbsp;&nbsp;- customer3<br />&nbsp;&nbsp;&nbsp;&nbsp;- customer4</code></li>
<li>To add a workspace, add the full path (preceded by a &#8216;\n&#8217;) to the end. To remove a workspace, remove the path any trailing &#8216;\n&#8217;</li>
</ol>
<p>The above has been tried out and works for Eclipse 3.4.2, 3.5, 3.5.2</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/uncategorized/addingremoving-workspaces-in-eclipse/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ANT Unable To Find A Javac Compiler</title>
		<link>http://dev.nirmalya.net/articles/uncategorized/ant-unable-to-find-a-javac-compiler</link>
		<comments>http://dev.nirmalya.net/articles/uncategorized/ant-unable-to-find-a-javac-compiler#comments</comments>
		<pubDate>Wed, 03 Feb 2010 09:26:05 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ANT]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=281</guid>
		<description><![CDATA[If ever you find yourself in a similar situation, BUILD FAILED C:\work\build.xml:188: Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to &#8220;C:\java\jre\6&#8243; Ensure the following: Ensure that JAVA_HOME is set Ensure that JAVA_HOME does not end with &#8216;bin&#8217; &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>If ever you find yourself in a similar situation,</p>
<blockquote><p>BUILD FAILED<br />
C:\work\build.xml:188: Unable to find a javac compiler;<br />
com.sun.tools.javac.Main is not on the classpath.<br />
Perhaps JAVA_HOME does not point to the JDK.<br />
It is currently set to &#8220;C:\java\jre\6&#8243;
</p></blockquote>
<p>Ensure the following:</p>
<ol>
<li>Ensure that <code>JAVA_HOME</code> is set</li>
<li>Ensure that <code>JAVA_HOME</code> does not end with &#8216;bin&#8217; &#8211; if it does, then ANT will not work as it will look for <code>tools.jar</code> under &#8220;<code>{JAVA_HOME}\lib</code>&#8220;</li>
<li>On command prompt, type <code>SET JAVA_HOME={Full path to JDK install}</code> (for example, <code>C:\java\jdk\160_16</code>)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/uncategorized/ant-unable-to-find-a-javac-compiler/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instantiating SimpleDateFormat Objects Consumes A Lot Of Memory</title>
		<link>http://dev.nirmalya.net/articles/java/instantiating-simpledateformat-objects-consumes-a-lot-of-memory</link>
		<comments>http://dev.nirmalya.net/articles/java/instantiating-simpledateformat-objects-consumes-a-lot-of-memory#comments</comments>
		<pubDate>Sun, 31 Jan 2010 17:42:30 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=272</guid>
		<description><![CDATA[Instantiating SimpleDateFormat objects can consume 3120 bytes per call.]]></description>
			<content:encoded><![CDATA[<p><strong>3120 bytes to be precise</strong>.</p>
<p>I had access to code which instantiated 3 <code>java.text.SimpleDateFormat</code> objects per method call. </p>
<p>I recently came across simple yet effective instrumentation to  query the size of a Java object, <a href="http://www.javamex.com/classmexer/" target="_blank" title="Link opens in new window">javamex</a>. Using it, I found that each instance of <code>java.text.SimpleDateFormat</code> has a deep memory usage of 3120 bytes! In comparison, a 3 character String, say, &#8220;<i>ABC</i>&#8221; has a deep memory usage of 48 bytes.</p>
<p><a href="http://eyalsch.wordpress.com/2009/05/29/sdf/trackback/" target="_blank" title="Link opens in new window">This article</a> suggests using an instance of the <code>java.text.SimpleDateFormat</code> per thread by making use of the <code>java.lang.ThreadLoca</code> class. </p>
<p>After referring to two articles online (which you can read <a href="http://www.javaspecialists.eu/archive/Issue172.html" target="_blank" title="Link opens in new window">here</a> &#038; <a href="http://www.ibm.com/developerworks/library/j-threads3.html" target="_blank" title="Link opens in new window">here</a>), I made some modifications to the code and sure enough, I no longer face the earlier problems related to memory usage.</p>
<p>Some excerpts. I created a per-thread Singleton, <code>DateUtil</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DateUtil
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> SDF1 sdf1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SDF1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> SDF2 sdf2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SDF2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Returns the SimpleDateFormat object</span>
  <span style="color: #666666; font-style: italic;">// for the date pattern &quot;ddMMMyyyy&quot;.</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">SimpleDateFormat</span> getSimpleDateFormat_ddMMMyyyy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#41;</span> sdf1.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Returns the SimpleDateFormat object</span>
  <span style="color: #666666; font-style: italic;">// for the date pattern &quot;EEE dd MMM yyyy&quot;.</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">SimpleDateFormat</span> getSimpleDateFormat_EEE_dd_MMM_yyyy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#41;</span> sdf2.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// A ThreadLocal subclass for the SimpleDateFormat</span>
  <span style="color: #666666; font-style: italic;">// for the date pattern &quot;ddMMMyyyy&quot;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> SDF1 <span style="color: #000000; font-weight: bold;">extends</span> ThreadLocal<span style="color: #339933;">&lt;</span>SimpleDateFormat<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">SimpleDateFormat</span> initialValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ddMMMyyyy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// A ThreadLocal subclass for the SimpleDateFormat </span>
  <span style="color: #666666; font-style: italic;">// for the date pattern &quot;EEE dd MMM yyyy&quot;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> SDF2 <span style="color: #000000; font-weight: bold;">extends</span> ThreadLocal<span style="color: #339933;">&lt;</span>SimpleDateFormat<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">SimpleDateFormat</span> initialValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;EEE dd MMM yyyy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the older code which previously instantiated a <code>java.text.SimpleDateFormat</code> object, I replaced it with the following,</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #003399;">SimpleDateFormat</span> travelDateFormat <span style="color: #339933;">=</span> DateUtil.<span style="color: #006633;">getSimpleDateFormat_ddMMMyyyy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">Date</span> date <span style="color: #339933;">=</span> travelDateFormat.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>strToParse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//where, strToParse is a String similar to &quot;31Jan2010&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/java/instantiating-simpledateformat-objects-consumes-a-lot-of-memory/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>noNamespace Problem When Using The XmlBean Task In ANT</title>
		<link>http://dev.nirmalya.net/articles/java/nonamespace-problem-when-using-the-xmlbean-task-in-ant</link>
		<comments>http://dev.nirmalya.net/articles/java/nonamespace-problem-when-using-the-xmlbean-task-in-ant#comments</comments>
		<pubDate>Tue, 19 Jan 2010 12:55:20 +0000</pubDate>
		<dc:creator>nirmalya</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[XmlBean]]></category>
		<category><![CDATA[xsd]]></category>
		<category><![CDATA[xsdconfig]]></category>

		<guid isPermaLink="false">http://dev.nirmalya.net/articles/?p=267</guid>
		<description><![CDATA[Here&#8217;s something that worked for me after having spent several hours on it. First the relevant part of the build.xml file. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 &#60;copy todir=&#34;${build.dir}${file.separator}schemaSrc&#34;&#62; &#60;fileset dir=&#34;${schemas.dir}&#34;&#62; &#60;include name=&#34;*.xsd&#34;/&#62; &#60;include name=&#34;*.xsdconfig&#34;/&#62; &#60;/fileset&#62; &#60;/copy&#62; &#60;path id=&#34;xmlbeans.path&#34;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s something that worked for me after having spent several hours on it. First the relevant part of the <code>build.xml</code> file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${build.dir}${file.separator}schemaSrc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${schemas.dir}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*.xsd&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*.xsdconfig&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;path</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;xmlbeans.path&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${lib.dir}/xmlbeans&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;xbean.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jsr173_1.0_api.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;xmlbeans.compiler&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;javac1.5&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;xmlbean&quot;</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;org.apache.xmlbeans.impl.tool.XMLBean&quot;</span> </span>
<span style="color: #009900;">             <span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;${toString:xmlbeans.path}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xmlbean</span> <span style="color: #000066;">schema</span>=<span style="color: #ff0000;">&quot;${build.dir}${file.separator}schemaSrc&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;schemas.jar&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">srcgendir</span>=<span style="color: #ff0000;">&quot;${build.dir}&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">debug</span>=<span style="color: #ff0000;">&quot;on&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;${toString:xmlbeans.path}&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">javasource</span>=<span style="color: #ff0000;">&quot;1.5&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>A sample <code>.xsd</code> file,</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:schema</span> <span style="color: #000066;">xmlns:xsd</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Employee&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SSN&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Name&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;DateOfBirth&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:date&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EmployeeType&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Salary&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:long&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:schema<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>A sample <code>.xsdconfig</code> file,</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xb:config</span> <span style="color: #000066;">xmlns:xb</span>=<span style="color: #ff0000;">&quot;http://xml.apache.org/xmlbeans/2004/02/xbean/config&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xb:namespace</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;##any&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xb:package<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.acompany.xsd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xb:package<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xb:namespace<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xb:config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://dev.nirmalya.net/articles/java/nonamespace-problem-when-using-the-xmlbean-task-in-ant/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

