<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Sieze&#039;s Blog</title>
	<atom:link href="http://sieze.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sieze.wordpress.com</link>
	<description>Yet another Java blog</description>
	<lastBuildDate>Wed, 25 Jan 2012 21:12:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sieze.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Sieze&#039;s Blog</title>
		<link>http://sieze.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sieze.wordpress.com/osd.xml" title="Sieze&#039;s Blog" />
	<atom:link rel='hub' href='http://sieze.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Keyboard and mouse stop working in Virtualbox guest</title>
		<link>http://sieze.wordpress.com/2011/02/09/keyboard-and-mouse-stop-working-in-virtualbox-guest/</link>
		<comments>http://sieze.wordpress.com/2011/02/09/keyboard-and-mouse-stop-working-in-virtualbox-guest/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 16:14:48 +0000</pubDate>
		<dc:creator>sieze</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[reboot]]></category>
		<category><![CDATA[stop]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[virtualbox]]></category>
		<category><![CDATA[working]]></category>

		<guid isPermaLink="false">http://sieze.wordpress.com/2011/02/09/keyboard-and-mouse-stop-working-in-virtualbox-guest/</guid>
		<description><![CDATA[If you ever experience your mouse and or keyboard not working in your&#160;Virtualbox guest OS and the only way to make them work again is rebooting, try to&#160;install the following packages: sudo apt-get install scim-bridge-client-qt scim-bridge-client-gtk -Sieze<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=35&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>If you ever experience your mouse and or keyboard not working in your&nbsp;Virtualbox guest OS and the only way to make them work again is rebooting, try to&nbsp;install the following packages:</div>
<div></div>
<div><span style="font-family:'courier new', courier;">sudo apt-get install scim-bridge-client-qt scim-bridge-client-gtk</span></div>
<div></div>
<div><span style="font-family:'andale mono', times;">-Sieze</span></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sieze.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sieze.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sieze.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sieze.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sieze.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sieze.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sieze.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sieze.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sieze.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sieze.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sieze.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sieze.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sieze.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sieze.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=35&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sieze.wordpress.com/2011/02/09/keyboard-and-mouse-stop-working-in-virtualbox-guest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0666eadbf6ec6fa8938ca73c0cee93d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sieze</media:title>
		</media:content>
	</item>
		<item>
		<title>How to mount a windows shared drive with a name containing spaces</title>
		<link>http://sieze.wordpress.com/2011/01/10/how-to-mount-a-windows-shared-drive-with-a-name-containing-spaces/</link>
		<comments>http://sieze.wordpress.com/2011/01/10/how-to-mount-a-windows-shared-drive-with-a-name-containing-spaces/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 13:20:35 +0000</pubDate>
		<dc:creator>sieze</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[drive]]></category>
		<category><![CDATA[folder]]></category>
		<category><![CDATA[fstab]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[shared]]></category>
		<category><![CDATA[space]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://sieze.wordpress.com/2011/01/10/how-to-mount-a-windows-shared-drive-with-a-name-containing-spaces/</guid>
		<description><![CDATA[If you are trying to mount a Windows shared folder that has its name containing spaces you can easily mount it sticking 40 instead the space character: eg.: If the box is at the address:&#160;192.168.0.15, and the name of the shared folder is &#8220;Name with spaces&#8221; you can add the following line into your /etc/fstab [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=34&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are trying to mount a Windows shared folder that has its name containing spaces you can easily mount it sticking 40 instead the space character:</p>
<p>eg.:</p>
<p>If the box is at the address:&nbsp;192.168.0.15, and the name of the shared folder is &#8220;Name with spaces&#8221;</p>
<p>you can add the following line into your /etc/fstab</p>
<p>&nbsp;</p>
<p>//192.168.0.15/Name40with40spaces /mnt/name-with-spaces bla bla bla</p>
<p>-Sieze</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sieze.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sieze.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sieze.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sieze.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sieze.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sieze.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sieze.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sieze.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sieze.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sieze.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sieze.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sieze.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sieze.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sieze.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=34&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sieze.wordpress.com/2011/01/10/how-to-mount-a-windows-shared-drive-with-a-name-containing-spaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0666eadbf6ec6fa8938ca73c0cee93d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sieze</media:title>
		</media:content>
	</item>
		<item>
		<title>Execute a command via SSH and terminate the connection without waiting for the command to finish</title>
		<link>http://sieze.wordpress.com/2010/12/09/execute-a-command-via-ssh-and-terminate-the-connection-without-waiting-for-the-command-to-finish/</link>
		<comments>http://sieze.wordpress.com/2010/12/09/execute-a-command-via-ssh-and-terminate-the-connection-without-waiting-for-the-command-to-finish/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 10:37:04 +0000</pubDate>
		<dc:creator>sieze</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[err]]></category>
		<category><![CDATA[nohup]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[out]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[std]]></category>
		<category><![CDATA[terminate]]></category>

		<guid isPermaLink="false">http://sieze.wordpress.com/2010/12/09/execute-a-command-via-ssh-and-terminate-the-connection-without-waiting-for-the-command-to-finish/</guid>
		<description><![CDATA[A few days ago I was trying to update the script used to build the application on which I&#8217;m working. Together with the build I also wanted to integrate the script so to release the app on test boxes and restart the JBoss instance. While the stop was working as a piece of cake, the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=33&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few days ago I was trying to update the script used to build the application on which I&#8217;m working. Together with the build I also wanted to integrate the script so to release the app on test boxes and restart the JBoss instance.</p>
<p>While the stop was working as a piece of cake, the restart of the server was keeping my ssh connection alive, and causing the release script to not finish.</p>
<p>After a bit of googling that the ssh syntax you&#8217;ll have to use if you want to send a command via ssh, redirect std out/err, and close the ssh connection:</p>
<p><span style="font-family:'andale mono', times;">ssh username@host &#8220;nohup command_to_execute &gt; /dev/null 2&gt;&amp;1 &gt; /../log_folder/log_file &amp;&#8221;</span></p>
<p><span style="font-family:'andale mono', times;"><span style="font-family:Helvetica, Arial, sans-serif;">Hope this will help someone of you out there <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </span></span></p>
<p>&nbsp;</p>
<p><span style="font-family:'andale mono', times;"><span style="font-family:Helvetica, Arial, sans-serif;">-Sieze</span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sieze.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sieze.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sieze.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sieze.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sieze.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sieze.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sieze.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sieze.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sieze.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sieze.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sieze.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sieze.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sieze.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sieze.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=33&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sieze.wordpress.com/2010/12/09/execute-a-command-via-ssh-and-terminate-the-connection-without-waiting-for-the-command-to-finish/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0666eadbf6ec6fa8938ca73c0cee93d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sieze</media:title>
		</media:content>
	</item>
		<item>
		<title>Meaning of load average of the top Linux command</title>
		<link>http://sieze.wordpress.com/2010/12/09/mapping-a-many-to-many-join-table-with-extra-column-using-jpa-2/</link>
		<comments>http://sieze.wordpress.com/2010/12/09/mapping-a-many-to-many-join-table-with-extra-column-using-jpa-2/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 09:45:00 +0000</pubDate>
		<dc:creator>sieze</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[average]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[top]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://sieze.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa-2/</guid>
		<description><![CDATA[Meaning of &#8220;load average&#8221; of the top Linux command The &#8220;load average&#8221; information given by the top command is of&#160;fundamental&#160;importance. But how to correctly understand the meaning of it? Which value are bad? Which good? This article is just simply brilliant in&#160;explaining&#160;how to interpret this value: http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages Enjoy! -Sieze<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=30&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Meaning of &#8220;load average&#8221; of the top Linux command</h3>
<p>The &#8220;load average&#8221; information given by the top command is of&nbsp;fundamental&nbsp;importance. But how to correctly understand the meaning of it? Which value are bad? Which good?</p>
<p>This article is just simply brilliant in&nbsp;explaining&nbsp;how to interpret this value: <a title="Understanding load averages" href="http://ppowerex00.inhouse.paddypower.com/exchweb/bin/redir.asp?URL=http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages" target="_blank">http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages</a></p>
<p>Enjoy!</p>
<p>-Sieze</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sieze.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sieze.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sieze.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sieze.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sieze.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sieze.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sieze.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sieze.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sieze.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sieze.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sieze.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sieze.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sieze.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sieze.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=30&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sieze.wordpress.com/2010/12/09/mapping-a-many-to-many-join-table-with-extra-column-using-jpa-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0666eadbf6ec6fa8938ca73c0cee93d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sieze</media:title>
		</media:content>
	</item>
		<item>
		<title>Mapping a many-to-many join table with extra column using JPA</title>
		<link>http://sieze.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/</link>
		<comments>http://sieze.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 01:43:57 +0000</pubDate>
		<dc:creator>sieze</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[extra]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[many-to-many]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://sieze.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/</guid>
		<description><![CDATA[Intro It is not straightforward to realise a many-to-many association with JPA when in the join table there is at least an extra column. In this small tutorial I’m going to show how to design entity objects that will handle the many-to-many relation and which annotations are needed in order to fix a redundancy that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=12&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Intro</h3>
<p>It is not straightforward to realise a many-to-many association with JPA when in the join table there is at least an extra column. In this small tutorial I’m going to show how to design entity objects that will handle the many-to-many relation and which annotations are needed in order to fix a redundancy that we will see in the solution adopted in the following wiki.</p>
<p>This tutorial is a mix up of different sources. The first solution I’m going to show is the one suggested in a wiki.</p>
<h3>Mapping a Join Table with Additional Columns (in a JPA pure style)</h3>
<p>Source: <a href="http://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Additional_columns_in_join_table.">en.wikibooks.org</a></p>
<blockquote><p>A frequent problem is that two classes have a ManyToMany relationship, but the relational join table has additional data. For example if Employee has a ManyToMany with Project but the PROJ_EMP join table also has an IS_TEAM_LEAD column. In this case the best solution is to create a class that models the join table. So an ProjectAssociation class would be created. It would have a ManyToOne to Employee and Project, and attributes for the additional data. Employee and Project would have a OneToMany to the ProjectAssociation. Some JPA providers also provide additional support for mapping to join tables with additional data.</p>
<p>Unfortunately mapping this type of model becomes more complicated in JPA because it requires a composite primary key. The association object&#8217;s Id is composed of the Employee and Project ids. The JPA spec does not allow an Id to be used on a ManyToOne so the association class must have two duplicate attributes to also store the ids, and use an IdClass, these duplicate attributes must be kept in synch with the ManyToOne attributes. Some JPA providers may allow a ManyToOne to be part of an Id, so this may be simpler with some JPA providers. To make your life simpler, I would recommend adding a generated Id attribute to the association class. This will give the object a simpler Id and not require duplicating the Employee and Project ids.</p>
<p>This same pattern can be used no matter what the additional data in the join table is. Another usage is if you have a Map relationship between two objects, with a third unrelated object or data representing the Map key. The JPA spec requires that the Map key be an attribute of the Map value, so the association object pattern can be used to model the relationship.</p>
<p>If the additional data in the join table is only required on the database and not used in Java, such as auditing information, it may also be possible to use database triggers to automatically set the data.</p>
</blockquote>
<h4>Example join table association object annotations</h4>
<p>&#160;</p>
<div class="wlWriterEditableSmartContent" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:cd2f8a4e-6ce4-49c4-8f53-7aee9c69551a" style="display:inline;float:none;margin:0;padding:0;">
<pre class="brush: java; gutter: true; first-line: 1; tab-size: 4;  toolbar: true; ">@Entity
public class Employee {
  @Id
  private long id;
  ...
  @OneToMany
  private List&lt;ProjectAssociation&gt; projects;
}</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>&#160;</p>
<p>&#160;</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d35db2c9-924f-410a-bcf0-7e0124a37010" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">@Entity
</span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> Employee {
  @Id
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">long</span><span style="color:#000000;"> id;
  ...
  @OneToMany
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProjectAssociation</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> projects;
}
</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>&#160;</p>
</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:aa61504e-dd36-43b9-af63-5fc3a6665bb1" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">@Entity
</span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> Project {
  @Id
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">long</span><span style="color:#000000;"> id;
  ...
  @OneToMany
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProjectAssociation</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> employees;
  ...
  </span><span style="color:#008000;">//</span><span style="color:#008000;"> Add an employee to the project.
  </span><span style="color:#008000;">//</span><span style="color:#008000;"> Create an association object for the relationship and set its' data.</span><span style="color:#008000;">
</span><span style="color:#000000;">  </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> addEmployee(Employee employee, </span><span style="color:#0000FF;">boolean</span><span style="color:#000000;"> teamLead) {
    ProjectAssociation association </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ProjectAssociation();
    association.setEmployee(employee);
    association.setProject(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">);
    association.setEmployeeId(employee.getId());
    association.setProjectId(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.getId());
    association.setIsTeamLead(teamLead);

    employees.add(association);
  }
}
</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:2c2914ac-a0b5-49cb-999b-46acff27b5e9" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">@Entity
@Table(name</span><span style="color:#000000;">=</span><span style="color:#000000;">"</span><span style="color:#000000;">PROJ_EMP</span><span style="color:#000000;">"</span><span style="color:#000000;">)
@IdClass(ProjectAssociationId.</span><span style="color:#0000FF;">class</span><span style="color:#000000;">)
</span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> ProjectAssociation {
  @Id
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">long</span><span style="color:#000000;"> employeeId;
  @Id
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">long</span><span style="color:#000000;"> projectId;
  @Column(</span><span style="color:#000000;">"</span><span style="color:#000000;">IS_PROJECT_LEAD</span><span style="color:#000000;">"</span><span style="color:#000000;">)
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">boolean</span><span style="color:#000000;"> isProjectLead;
  @ManyToOne
  @PrimaryKeyJoinColumn(name</span><span style="color:#000000;">=</span><span style="color:#000000;">"</span><span style="color:#000000;">EMPLOYEEID</span><span style="color:#000000;">"</span><span style="color:#000000;">, referencedColumnName</span><span style="color:#000000;">=</span><span style="color:#000000;">"</span><span style="color:#000000;">ID</span><span style="color:#000000;">"</span><span style="color:#000000;">)
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Employee employee;
  @ManyToOne
  @PrimaryKeyJoinColumn(name</span><span style="color:#000000;">=</span><span style="color:#000000;">"</span><span style="color:#000000;">PROJECTID</span><span style="color:#000000;">"</span><span style="color:#000000;">, referencedColumnName</span><span style="color:#000000;">=</span><span style="color:#000000;">"</span><span style="color:#000000;">ID</span><span style="color:#000000;">"</span><span style="color:#000000;">)
  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Project project;
  ...
}
</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>&#160;</p>
</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:eec0977a-786b-409f-b810-23e9a3090c53" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> ProjectAssociationId {

  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">long</span><span style="color:#000000;"> employeeId;

  </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">long</span><span style="color:#000000;"> projectId;
  ...
}
</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>&#160;</p>
<p>As you can see in this solution the ProjectAssociation class contains twice the information related to Employee and Project. As explained above, this is due to JPA specification. Googling I found another solution to this problem that allowed me to avoid the redundancy.</p>
<h3>Hibernate annotations: The many-to-many association with composite key (in a pure JPA style without redundancy)</h3>
<p>Source: <a href="http://boris.kirzner.info/blog/archives/2008/07/19/hibernate-annotations-the-many-to-many-association-with-composite-key/">boris.kirzner.info</a></p>
<p>This post contains an evolution of another solution realized in 2006. Since things changed a bit in the meanwhile, the original solution was not the best.</p>
<p>Basically what the author is trying to do is to hold a relation between three item: Produc, Item and ProductItem.</p>
<p>Here is the last part of the post in which the author introduce the solution:</p>
<blockquote>
<p>The database part is the same: we have three tables (item, product and product_item), two POJO classes, and two classes for a many-to-many association and its primary key. The main difference from Marsel’s solution is that I’m not using any kind of “fake” properties on ProductItem in order to reference Item and Product, but just a plain transient properties delegating to ProductItemPk.</p>
</blockquote>
<p>Here is the source:</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d7a40b46-5ee9-4ed0-a613-96ff9e6d06c1" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">@Entity
@Table(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">item</span><span style="color:#000000;">"</span><span style="color:#000000;">)
</span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> Item {

    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Integer id;
    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> String name;
    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> productItems </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> LinkedList</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Item() {
    }

    @Id
    @GenericGenerator(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">generator</span><span style="color:#000000;">"</span><span style="color:#000000;">, strategy </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">increment</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    @GeneratedValue(generator </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">generator</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    @Column(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">item_id</span><span style="color:#000000;">"</span><span style="color:#000000;">, nullable </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">)
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Integer getId() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.id;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setId(Integer id) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.id </span><span style="color:#000000;">=</span><span style="color:#000000;"> id;
    }

    @Column(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">name</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String getName() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.name;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setName(String name) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.name </span><span style="color:#000000;">=</span><span style="color:#000000;"> name;
    }

    @OneToMany(fetch </span><span style="color:#000000;">=</span><span style="color:#000000;"> FetchType.LAZY, mappedBy </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">pk.item</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> getProductItems() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.productItems;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setProductItems(List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> productItems) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.productItems </span><span style="color:#000000;">=</span><span style="color:#000000;"> productItems;
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>&#160;</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5aeb8f47-720c-4c02-8dfb-9aa5285517cb" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">@Entity
@Table(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">product</span><span style="color:#000000;">"</span><span style="color:#000000;">)
</span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> Product {

    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Integer id;
    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> String name;
    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> productItems </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> LinkedList</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Product() {
    }

    @Id
    @GenericGenerator(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">generator</span><span style="color:#000000;">"</span><span style="color:#000000;">, strategy </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">increment</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    @GeneratedValue(generator </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">generator</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    @Column(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">product_id</span><span style="color:#000000;">"</span><span style="color:#000000;">, nullable </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">)
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Integer getId() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.id;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setId(Integer id) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.id </span><span style="color:#000000;">=</span><span style="color:#000000;"> id;
    }

    @Column(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">name</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String getName() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.name;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setName(String name) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.name </span><span style="color:#000000;">=</span><span style="color:#000000;"> name;
    }

    @OneToMany(fetch </span><span style="color:#000000;">=</span><span style="color:#000000;"> FetchType.LAZY, mappedBy </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">pk.product</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> getProductItems() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.productItems;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setProductItems(List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> productItems) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.productItems </span><span style="color:#000000;">=</span><span style="color:#000000;"> productItems;
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>&#160;</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f3a36dc0-1280-4c2c-8f83-c8d37876a7ef" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">@Entity
@Table(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">product_item</span><span style="color:#000000;">"</span><span style="color:#000000;">)
@AssociationOverrides({
@AssociationOverride(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">pk.item</span><span style="color:#000000;">"</span><span style="color:#000000;">, joinColumns </span><span style="color:#000000;">=</span><span style="color:#000000;"> @JoinColumn(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">item_id</span><span style="color:#000000;">"</span><span style="color:#000000;">)),
@AssociationOverride(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">pk.product</span><span style="color:#000000;">"</span><span style="color:#000000;">, joinColumns </span><span style="color:#000000;">=</span><span style="color:#000000;"> @JoinColumn(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">product_id</span><span style="color:#000000;">"</span><span style="color:#000000;">))
        })
</span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> ProductItem {

    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> ProductItemPk pk </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ProductItemPk();

    @EmbeddedId
    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> ProductItemPk getPk() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> pk;
    }

    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setPk(ProductItemPk pk) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.pk </span><span style="color:#000000;">=</span><span style="color:#000000;"> pk;
    }

    @Transient
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Item getItem() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> getPk().getItem();
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setItem(Item item) {
        getPk().setItem(item);
    }

    @Transient
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Product getProduct() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> getPk().getProduct();
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setProduct(Product product) {
        getPk().setProduct(product);
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">boolean</span><span style="color:#000000;"> equals(Object o) {
        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;"> </span><span style="color:#000000;">==</span><span style="color:#000000;"> o) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">;
        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (o </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">||</span><span style="color:#000000;"> getClass() </span><span style="color:#000000;">!=</span><span style="color:#000000;"> o.getClass()) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;

        ProductItem that </span><span style="color:#000000;">=</span><span style="color:#000000;"> (ProductItem) o;

        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (getPk() </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">?</span><span style="color:#000000;"> </span><span style="color:#000000;">!</span><span style="color:#000000;">getPk().equals(that.getPk()) : that.getPk() </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;

        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> hashCode() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> (getPk() </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">?</span><span style="color:#000000;"> getPk().hashCode() : </span><span style="color:#000000;">0</span><span style="color:#000000;">);
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>&#160;</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:319c510f-4256-4f38-a43d-beeb554c9bdc" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">@Embeddable
</span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> ProductItemPk </span><span style="color:#0000FF;">implements</span><span style="color:#000000;"> Serializable {

    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Item item;
    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Product product;

    @ManyToOne
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Item getItem() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> item;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setItem(Item item) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.item </span><span style="color:#000000;">=</span><span style="color:#000000;"> item;
    }

    @ManyToOne
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Product getProduct() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> product;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setProduct(Product product) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.product </span><span style="color:#000000;">=</span><span style="color:#000000;"> product;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">boolean</span><span style="color:#000000;"> equals(Object o) {
        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;"> </span><span style="color:#000000;">==</span><span style="color:#000000;"> o) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">;
        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (o </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">||</span><span style="color:#000000;"> getClass() </span><span style="color:#000000;">!=</span><span style="color:#000000;"> o.getClass()) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;

        ProductItemPk that </span><span style="color:#000000;">=</span><span style="color:#000000;"> (ProductItemPk) o;

        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (item </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">?</span><span style="color:#000000;"> </span><span style="color:#000000;">!</span><span style="color:#000000;">item.equals(that.item) : that.item </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;
        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (product </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">?</span><span style="color:#000000;"> </span><span style="color:#000000;">!</span><span style="color:#000000;">product.equals(that.product) : that.product </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;

        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> hashCode() {
        </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> result;
        result </span><span style="color:#000000;">=</span><span style="color:#000000;"> (item </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">?</span><span style="color:#000000;"> item.hashCode() : </span><span style="color:#000000;">0</span><span style="color:#000000;">);
        result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">31</span><span style="color:#000000;"> </span><span style="color:#000000;">*</span><span style="color:#000000;"> result </span><span style="color:#000000;">+</span><span style="color:#000000;"> (product </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">?</span><span style="color:#000000;"> product.hashCode() : </span><span style="color:#000000;">0</span><span style="color:#000000;">);
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> result;
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>&#160;</p>
<p>This solution is perfect from a model point of view. I used this solution in my project and together with Spring, Hibernate and Maven I’ve been able to generate the schema in an automatic fashion (hbm2dll plugin). The schema produced is exactly what you would expect.</p>
<p>Unfortunately JPA doesn’t allow developer to use this configuration to work with inserts and updates. For instance if you have an Item object with few ProductItem and you perform an insert on the Item, ProductItem object contained in the list will not be inserted in the database. Same stuff happens for a Product and its ProductItem list.</p>
<p>JPA in this case won’t help us anymore. The only way to make inserts and updates to work in cascade, we must recur to provider’s specific annotation. The source code below is the final evolution of the previous example. The JPA provider I used is Hibernate.</p>
<p>Here is the code for the Product class, use the same annotation for the Item class as well and Hibernate will take care to insert/update ProductItem (if any) as well.</p>
<div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9e62addc-24e6-4dd7-91ea-ee897c5352ca" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">@Entity
@Table(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">product</span><span style="color:#000000;">"</span><span style="color:#000000;">)
</span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> Product {

    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Integer id;
    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> String name;
    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> productItems </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> LinkedList</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Product() {
    }

    @Id
    @GenericGenerator(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">generator</span><span style="color:#000000;">"</span><span style="color:#000000;">, strategy </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">increment</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    @GeneratedValue(generator </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">generator</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    @Column(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">product_id</span><span style="color:#000000;">"</span><span style="color:#000000;">, nullable </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">)
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Integer getId() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.id;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setId(Integer id) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.id </span><span style="color:#000000;">=</span><span style="color:#000000;"> id;
    }

    @Column(name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">name</span><span style="color:#000000;">"</span><span style="color:#000000;">)
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String getName() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.name;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setName(String name) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.name </span><span style="color:#000000;">=</span><span style="color:#000000;"> name;
    }

    </span><span style="color:#008000;">/*</span><span style="color:#008000;">
     * Here is the annotation to add in order to
     * Hibernate to automatically insert and update
     * ProducItems (if any)
     </span><span style="color:#008000;">*/</span><span style="color:#000000;">
    @OneToMany(fetch </span><span style="color:#000000;">=</span><span style="color:#000000;"> FetchType.LAZY, mappedBy </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">pk.product</span><span style="color:#000000;">"</span><span style="color:#000000;">, cascade </span><span style="color:#000000;">=</span><span style="color:#000000;">
    {CascadeType.PERSIST, CascadeType.MERGE})
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
    org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> getProductItems() {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.productItems;
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setProductItems(List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ProductItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> productItems) {
        </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.productItems </span><span style="color:#000000;">=</span><span style="color:#000000;"> productItems;
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>&#160;</p>
<p>Since I only have experience with Hibernate I invite all the reader that have expertise with other JPA provider to reply to this post with the solution offered by other framework such as iBatis.</p>
<p>Thanks for have reading this tutorial and feel free to reply with comments.</p>
<p>-Sieze</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sieze.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sieze.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sieze.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sieze.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sieze.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sieze.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sieze.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sieze.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sieze.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sieze.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sieze.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sieze.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sieze.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sieze.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=12&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sieze.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0666eadbf6ec6fa8938ca73c0cee93d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sieze</media:title>
		</media:content>
	</item>
		<item>
		<title>I gotta feeling</title>
		<link>http://sieze.wordpress.com/2009/08/30/i-gotta-feeling/</link>
		<comments>http://sieze.wordpress.com/2009/08/30/i-gotta-feeling/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 03:13:32 +0000</pubDate>
		<dc:creator>sieze</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sieze.wordpress.com/?p=8</guid>
		<description><![CDATA[I think there will never be more perfect night to start my blogging activity. First of all I really think there&#8217;s something wrong with myself. So far, every time I asked to someone to guess where I&#8217;m from they never guessed at the first shoot. I received the most various answers, from Romania to Egypt, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=8&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I think there will never be more perfect night to start my blogging activity.</p>
<p>First of all I really think there&#8217;s something wrong with myself. So far, every time I asked to someone to guess where I&#8217;m from they never guessed at the first shoot. I received the most various answers, from Romania to Egypt, Mexico, Lithuania and so on.</p>
<p>Only few times someone said &#8220;Italy&#8221;!</p>
<p>Let&#8217;s introduce myself now. My name is Giovanni, a very common Italian name. I&#8217;m from Naples and I&#8217;m a software developer. I resigned in 2008 to move to Ireland and check how the Irish tiger was. In this first Irish year, hundreds of things happened. Troubles in private life, successes at work, new friends, new habits, nights spent at discos and pints, pints and still more pints of beer.</p>
<p>Few days ago I was visiting a tech-y blog here on wordpress and I fell in love with the its style so I decided that soon or later I had to open my own blog and begin, from time to time, to share something about myself such as adventures, trips and wannabe technical articles on the Java world.</p>
<p>It&#8217;s time to lay back and get some rest. Tomorrow (or should I say &#8220;later&#8221;?!) I have go to visit Dun Laoghaire with some friends.</p>
<p>It&#8217;s funny how tonight begun and finished with &#8220;sweet dreams&#8221;&#8230; Few of you, or maybe no one, will understand this, but it&#8217;ll be handy for me to remember that the just finished night might have been the begin of a new chapter of my life.</p>
<p>-Sieze</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sieze.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sieze.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sieze.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sieze.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sieze.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sieze.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sieze.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sieze.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sieze.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sieze.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sieze.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sieze.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sieze.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sieze.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sieze.wordpress.com&amp;blog=9220579&amp;post=8&amp;subd=sieze&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sieze.wordpress.com/2009/08/30/i-gotta-feeling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0666eadbf6ec6fa8938ca73c0cee93d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sieze</media:title>
		</media:content>
	</item>
	</channel>
</rss>
