<?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>Web2.0 Tutorials &#187; Eclipse</title>
	<atom:link href="http://www.zulutown.com/blog/category/eclipse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zulutown.com/blog</link>
	<description>All the Guides You Need to Become a Web2.0 Expert</description>
	<lastBuildDate>Mon, 13 Jul 2009 07:50:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hibernate, hashCode, equals and Eclipse</title>
		<link>http://www.zulutown.com/blog/2009/04/12/hibernate-hashcode-equals-and-eclipse/</link>
		<comments>http://www.zulutown.com/blog/2009/04/12/hibernate-hashcode-equals-and-eclipse/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 09:18:57 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[automatic generation]]></category>
		<category><![CDATA[bean]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[contains]]></category>
		<category><![CDATA[embeddedId]]></category>
		<category><![CDATA[equals]]></category>
		<category><![CDATA[fetch]]></category>
		<category><![CDATA[getters]]></category>
		<category><![CDATA[hashcode]]></category>
		<category><![CDATA[instanceof]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[lazy loading]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[proxy class]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=115</guid>
		<description><![CDATA[Java programmers use often Eclipse to write their code, and it&#8217;s common to rely on the Eclipse features to quickly generate the hashCode() and equals(Object obj) methods of the beans.
Working on a Hibernate based application, I often noticed unexpected issues, and after some in depth debugging I&#8217;ve found that probably some of these problems were [...]]]></description>
			<content:encoded><![CDATA[<p>Java programmers use often Eclipse to write their code, and it&#8217;s common to rely on the Eclipse features to quickly generate the <em>hashCode()</em> and <em>equals(Object obj)</em> methods of the beans.</p>
<p>Working on a Hibernate based application, I often noticed unexpected issues, and after some <em>in depth</em> debugging I&#8217;ve found that probably some of these problems were caused by the Eclipse automatic generation of <code>equals</code> method.</p>
<p>In my opinion, this is mostly caused by the fact that Hibernate generates on top of our <em>entity bean</em> classes other <em>proxy classes</em> that overrides the getters, and other methods in order to provide the <em>lazy loading</em> of data.</p>
<p>I.e.: When Hibernate loads from the DB a <code>Movie</code> bean, it will have, for example, an associated list of <code>MovieActor</code> objects. Obviously Hibernate will not fetch all the data related to every single actor, but anyway it will generate the <em>stub</em> for the MovieActor objects.</p>
<p>The programmer would be tempted to use code like this:</p>
<pre>Movie aMovie = getEntityManager.find(...);
MovieActor aMovieActor = getEntityManager.find(...);
if (aMovie.getActors().contains(aMovieActor)) {
	System.out.println(aMovieActor.getActor().getName() + " acted in the movie " + aMovie.getTitle());
}</pre>
<p>I noticed that <code>contains</code> method often returns <code>false</code> even if that actor really acted in that movie!<br />
After some long debugging sessions, my final idea is that the problem is how Eclipse automatically generated the <code>equals</code> method of <code>MovieActor</code> class:</p>
<pre>	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof MovieActor))
			return false;
		MovieActor other = (MovieActor) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}</pre>
<p>In this code <code>id</code> is an <code>@EmbeddedId</code> composed by the Actor and the Movie associations. What I believe that causes problems is: <strong><code>other.id</code></strong>!</p>
<p>This is because probably the Id of the <code>other</code> object hasn&#8217;t been loaded yet, and its fetching will happen on the calling of <code>getId()</code> of the proxy class built on MovieActor.</p>
<p>So, I changed the <code>equals</code> method this way:</p>
<pre>	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof MovieActor))
			return false;
		MovieActor other = (MovieActor) obj;
		if (id == null) {
			if (other.getId() != null)
				return false;
		} else if (!id.equals(other.getId()))
			return false;
		return true;
	}</pre>
<p>And after this little change, <code>contains</code> began to work correctly!</p>
<p>Another <strong>very important</strong> thing is to check <em>use &#8216;instanceof&#8217; to compare types</em> otherwise some ugly code would be generated.<br />
Some checks like <code>if (getClass() != obj.getClass())</code> would miserably fail when hibernate proxy classes are used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/04/12/hibernate-hashcode-equals-and-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java EE Web Application with Eclipse Ganymede</title>
		<link>http://www.zulutown.com/blog/2009/01/27/java-ee-web-application-with-eclipse-ganymede/</link>
		<comments>http://www.zulutown.com/blog/2009/01/27/java-ee-web-application-with-eclipse-ganymede/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 21:13:15 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[ganymede]]></category>
		<category><![CDATA[war]]></category>
		<category><![CDATA[web application]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=45</guid>
		<description><![CDATA[First of all setup Eclipse Ganymede for Java EE and add to it a Tomcat6 server, as described in my previous tutorial.
Choose, from the File menu New, Dynamic Web Project in the option panel, give a name to the project (i.e. Struts2-Rest), choose a Target Runtime (that you should have already defined, in my case, [...]]]></description>
			<content:encoded><![CDATA[<p>First of all setup Eclipse Ganymede for Java EE and add to it a Tomcat6 server, as described in my previous tutorial.</p>
<p>Choose, from the <em>File</em> menu <em>New, Dynamic Web Project</em> in the option panel, give a name to the project (i.e. <em>Struts2-Rest</em>), choose a Target Runtime (that you should have already defined, in my case, Apache Tomcat v.6.0) and click Next.</p>
<div id="attachment_46" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-46" title="New Dynamic Web Project" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/new-dynamic-web-project-300x288.png" alt="New Dynamic Web Project" width="300" height="288" /><p class="wp-caption-text">New Dynamic Web Project</p></div>
<p>Here you can define the web application context root, that&#8217;s the relative path where it will be accessibile, if you choose <code>Struts2-Rest</code> as context root, your application will be accessible on <code>http://www.yourserver.com/Struts2-Rest</code> or  <code>http://localhost:8080/Struts2-Rest</code> if you use the default Tomcat configuration provided by Eclipse (with the Tomcat HTTP Connector on the port 8080)</p>
<p>The <em>Content Directory</em> parameters defines the directory inside your project where is located the &#8220;root&#8221; of the .war you&#8217;re going to generate, use the default <code>WebContent</code> directory.</p>
<p>And, obviously, <em>Java Source Directory</em> defines the directory where your Java sources will be stored. Just for your information, after compilation, the generated <code>.class</code> files are automatically moved by Eclipse into <code>WebContent/WEB-INF/classes</code>.</p>
<div id="attachment_47" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-47" title="New Dynamic Web Project - Web Module" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/new-dynamic-web-project-web-module-300x288.png" alt="New Dynamic Web Project - Web Module" width="300" height="288" /><p class="wp-caption-text">New Dynamic Web Project - Web Module</p></div>
<p>Just click finish. Your brand new project will appear in the <em>Project Explorer</em></p>
<div id="attachment_48" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-48" title="Project Explorer - New Web Project Created" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/web-project-created-300x195.png" alt="Project Explorer - New Web Project Created" width="300" height="195" /><p class="wp-caption-text">Project Explorer - New Web Project Created</p></div>
<p>The Deployment Descriptor is obviously associated with the <em>web.xml</em> file. The Java Resources (<code>src</code>) contains your source code, and <code>WebContent</code> contains all the  <code>.jsp</code> files, the static contents (images, css, javascripts) and the WEB-INF directory of your .war that will contain the compiled classes (in <code>/WEB-INF/classes</code>) and the libraries (in <code>/WEB-INF/lib</code>).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/01/27/java-ee-web-application-with-eclipse-ganymede/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setup Tomcat6 on Eclipse</title>
		<link>http://www.zulutown.com/blog/2009/01/18/setup-tomcat6-on-eclipse/</link>
		<comments>http://www.zulutown.com/blog/2009/01/18/setup-tomcat6-on-eclipse/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 23:10:07 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[ganymede]]></category>
		<category><![CDATA[tomcat6]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=5</guid>
		<description><![CDATA[Download Eclipse IDE for Java EE Developers from http://www.eclipse.org/downloads/ and tomcat6 from http://tomcat.apache.org/download-60.cgi
Extract both of them where you prefer. I extracted Eclipse in /opt/eclipse and Tomcat in /opt/tomcat6), then run Eclipse.
When you&#8217;ll run eclipse it asks you about creating a new workspace (that will be used to store all of your projects), so create a [...]]]></description>
			<content:encoded><![CDATA[<p>Download Eclipse IDE for Java EE Developers from <a href="http://www.eclipse.org/downloads/">http://www.eclipse.org/downloads/</a> and tomcat6 from <a href="http://tomcat.apache.org/download-60.cgi">http://tomcat.apache.org/download-60.cgi</a></p>
<p>Extract both of them where you prefer. I extracted Eclipse in /opt/eclipse and Tomcat in /opt/tomcat6), then run Eclipse.</p>
<p>When you&#8217;ll run eclipse it asks you about creating a new workspace (that will be used to store all of your projects), so create a <em>workspace</em>, usually somewhere in your user home directory.</p>
<p>When Eclipse is up and running, choose <em>preferences</em> from the <em>window</em> menu. Choose from the bar on the left: Server, Runtime Environments.</p>
<div id="attachment_6" class="wp-caption aligncenter" style="width: 247px"><img class="size-medium wp-image-6" title="Preferences" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/screenshot-preferences-237x300.png" alt="Preferences window in Eclipse" width="237" height="300" /><p class="wp-caption-text">Preferences</p></div>
<p>Click the button <em>Add</em>, choose <em>Apache Tomcat 6</em>.</p>
<div id="attachment_7" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-7" title="New Server Runtime Environment" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/screenshot-new-server-runtime-environment-300x275.png" alt="New Server Runtime Environment" width="300" height="275" /><p class="wp-caption-text">New Server Runtime Environment</p></div>
<p>In the next page, <em>browse</em> on your disk and choose the directory where you previously extracted Tomcat. In my case it&#8217;s /opt/tomcat6. Finally click Finish.</p>
<div id="attachment_9" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-9" title="New Server Runtime Environment - Server Path" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/screenshot-new-server-runtime-environment-1-300x275.png" alt="New Server Runtime Environment - Server Path" width="300" height="275" /><p class="wp-caption-text">New Server Runtime Environment - Server Path</p></div>
<p>Well, until now we have just told to our workspace where Tomcat &#8220;installation&#8221; is located on our disk.</p>
<p>But, if we wish to run Java Web Applications within Eclipse, we should setup a Server and eventually assign to it a specific configuration.<br />
Go in the <em>Servers</em> view, right click and choose New, then Server.</p>
<p>Select &#8220;Tomcat v6.0 Server&#8221; as server type (or probably it will be automatically pre-selected), then, in the <em>Server Runtime environment</em> select box you&#8217;ll have to choose &#8220;Apache Tomcat v6.0&#8243; (that&#8217;s probably the only available option.</p>
<div id="attachment_39" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-39" title="New Tomcat Server in Eclipse" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/eclipse-new-tomcat-server-300x290.png" alt="New Tomcat Server in Eclipse" width="300" height="290" /><p class="wp-caption-text">New Tomcat Server in Eclipse</p></div>
<p>Click on Next, Eclipse will prompt you to eventually add (or remove) web projects from this Server, in this case, if your workspace is empty you&#8217;ll have not any project to add. So, click <em>Finish</em>.</p>
<div id="attachment_40" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-40" title="Add remove Eclipse projects from Tomcat" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/eclipse-add-remove-projects-from-tomcat-300x290.png" alt="eclipse-add-remove-projects-from-tomcat" width="300" height="290" /><p class="wp-caption-text">Add remove Eclipse projects from Tomcat</p></div>
<p>In the <em>Servers</em> panel, you will see the Tomcat you just added, and in the <em>Project Explorer</em> view, a new Server configuration will  magical appear.</p>
<p>So you can edit the configuration file <code>server.xml</code> as you prefer, change AJP or HTTP connector ports and so on, start/stop/debug the server and obviously add and remove projects from it.</p>
<div id="attachment_41" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-41" title="Editing Tomcat configuration in Eclipse" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/tomcat-configuration-300x177.png" alt="Editing Tomcat configuration in Eclipse" width="300" height="177" /><p class="wp-caption-text">Editing Tomcat configuration in Eclipse</p></div>
<p>It is also possible to add other server &#8220;instances&#8221;, just right click again in the &#8220;Servers&#8221; view, and follow the procedure described before.</p>
<p>In this way, you will just a single &#8220;Tomcat&#8221; binaries location (that you defined in the first step of this tutorial), but you&#8217;ll have the chance to add many instances of that server, each of them with its specific configuration (imagine the <code>/conf</code> directory of Tomcat) and its specific web application (imagine the <code>/webapps</code> directory).</p>
<div id="attachment_42" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-42" title="Multiple Tomcat Instances in Eclipse" src="http://www.zulutown.com/blog/wp-content/uploads/2009/01/eclipse-multiple-tomcat-instances-300x291.png" alt="Multiple Tomcat Instances in Eclipse" width="300" height="291" /><p class="wp-caption-text">Multiple Tomcat Instances in Eclipse</p></div>
<p>For the more expert ones, it is similar to have more instances on the same tomcat binaries defined on different <code>CATALINA_BASE</code> paths.</p>
<p>I hope this tutorial has been useful, please post any question or comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/01/18/setup-tomcat6-on-eclipse/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
