<?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>simonpena.com &#187; Pennybank</title>
	<atom:link href="http://simonpena.com/blog/category/proyectos/pennybank/feed/" rel="self" type="application/rss+xml" />
	<link>http://simonpena.com/blog</link>
	<description>Una mezcla heterogénea de tecnología y desvaríos</description>
	<lastBuildDate>Tue, 11 Oct 2011 19:14:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>See you in June</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/see-you-in-june/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=see-you-in-june</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/see-you-in-june/#comments</comments>
		<pubDate>Sat, 02 May 2009 18:08:00 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=67</guid>
		<description><![CDATA[I haven't typed a single line of code since the Easter Week Holidays. Besides my daily job, I should be finishing some assignments I've been given, so this personal project has been pushed back in my priorities stack. I'm not going to give up so easily: I think it's just a matter of time, and [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/see-you-in-june/' addthis:title='See you in June '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>I haven't typed a single line of code since the Easter Week Holidays. Besides my daily job, I should be finishing some assignments I've been given, so this personal project has been pushed back in my priorities stack. I'm not going to give up so easily: I think it's just a matter of time, and in the worst case I will be back here in June.It's a pitty, because the application is very close to a <em>functional-enough</em> state. Or maybe it is better this way, as I feel the urge to come back developing as soon as possible, instead of thinking that "<em>as it works right now, there's no need to keep working</em>".</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/see-you-in-june/' addthis:title='See you in June '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/see-you-in-june/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Undo, redo support using patterns</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/undo-redo-support-using-patterns/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=undo-redo-support-using-patterns</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/undo-redo-support-using-patterns/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 17:49:12 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[Command Pattern]]></category>
		<category><![CDATA[Composite Pattern]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Template method Pattern]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=65</guid>
		<description><![CDATA[More report progress regarding undo, redo and execute using design patterns.<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/undo-redo-support-using-patterns/' addthis:title='Undo, redo support using patterns '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>This Easter Week has been very productive. Although I didn't upload the screenshots as I said, I've made several interesting improvements.</p>
<ul>
<li>The delete menu item changes according to the current user interface selection. If an account is selected, it displays <em>delete account</em>. If an user is selected, it displays <em>delete user</em>, and if an account operation is selected, it displays <em>delete account operation</em>.</li>
<li>It is possible to undo/redo the actions made. The major improvement I pointed out on the previous post is almost done, so you can reverse the addition, edition and deletion of users, accounts and account operations.</li>
</ul>
<p>I've made a new hierarchy in the controller layer. I created the interface <a title="UIAction.java" href="http://code.google.com/p/pennybank/source/browse/trunk/src/main/java/com/googlecode/pennybank/swing/controller/actions/UIAction.java" target="_blank">UIAction</a>, with methods <em>execute</em>, <em>undo</em>, <em>redo</em> and <em>getName</em>. I created an abstract implementation, <a title="GenericAction.java" href="http://code.google.com/p/pennybank/source/browse/trunk/src/main/java/com/googlecode/pennybank/swing/controller/actions/GenericAction.java" target="_blank">GenericAction</a>, where I made <em>final</em> those methods -to avoid the concrete classes reimplementing them-, calling <em>doExecute</em>, <em>doUndo,</em> <em>doRedo</em> and <em>doGetName</em> (which currently doesn't make much sense), followed by a call to update (a private method which updates the information displayed on the main window).</p>
<p>The do<em>Wathever</em> methods are <em>protected</em> and <em>abstract</em>, so the actions extending GenericAction must override them. This way, each action implements its own behavior for that methods, but at the same time complying with the generic behavior without the an explicit call to <em>super</em>. It follows the <a title="Template method pattern" href="http://en.wikipedia.org/wiki/Template_method_pattern" target="_blank">Template method pattern</a>.</p>
<p>Besides, I made a <a title="CompositeAction.java" href="http://code.google.com/p/pennybank/source/browse/trunk/src/main/java/com/googlecode/pennybank/swing/controller/actions/CompositeAction.java" target="_blank">CompositeAction</a> class, following the <a title="Composite pattern" href="http://en.wikipedia.org/wiki/Composite_pattern" target="_blank">Composite pattern</a>, so several actions can be grouped into another.</p>
<p>This way, all the defined actions are commands, and the application itself has the responsibility of executing them. Whenever an action is executed, it is stored in an <em>undoable actions stack</em>, and its name is set in the edit menu, so you can read "Undo <em>actionName</em>". If you undo the action, the application takes it out from the stack, invokes its <em>undo </em>method, and adds it to the <em>redoable actions stack</em>. After that, its name will appear in the edit menu, displaying "Redo <em>actionName</em>". Again, if you redo the action, the application takes it out from that stack and invokes its <em>redo</em> method, adding it again to the <em>undoable actions stack</em>. And over and over again (as far as it is well implemented).</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/undo-redo-support-using-patterns/' addthis:title='Undo, redo support using patterns '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/undo-redo-support-using-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keep working hard</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/keep-working-hard/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=keep-working-hard</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/keep-working-hard/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 01:02:52 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[Command Pattern]]></category>
		<category><![CDATA[embedded database]]></category>
		<category><![CDATA[H2 database]]></category>
		<category><![CDATA[implementation]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=63</guid>
		<description><![CDATA[Some progress report<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/keep-working-hard/' addthis:title='Keep working hard '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>It's been a while since the last post, and some improvements have been made. I've added a context menu both to the navigation panel and the account operation table, and it is now possible to rename, edit and delete accounts, and edit and delete account operations. I've fixed the account operations table filters, so you can search within the comments and categories (or both) of the account operations. The field to be searched is selected in a search text box just like iTunes'.</p>
<p>The menu bar isn't completed yet: there are several operations which can't be accessed from there. But as the listeners and actions are made for the context menu, the work left is reduced to bind those actions to the main menu items.</p>
<p>The next major change involves re-factoring some of the actions, so the <a title="Command pattern" href="http://en.wikipedia.org/wiki/Command_pattern" target="_blank">Command Pattern</a> can be introduced: support for undo and redo should is the next target.</p>
<p>There's still another thing I have to put hours in: improving the application installation and configuration. Right now it involves downloading Maven, MySQL and JTA, and installing and configuring them. Several weeks ago I found <a title="H2 Database" href="http://www.h2database.com/" target="_blank">H2 Database</a>, and how easy it was to install and use it. I think it would be a lot easier for the final user to have his data in an embedded database, so the task left for me is to figure how to select the database placement, choose if that placement is a permanent one or can be changed even on runtime, and if it would even be possible to change between an embedded database or a server one.</p>
<p>I'm not sure which option should I prioritize... We'll see. And I'll upload some screenshots someday within this week.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/keep-working-hard/' addthis:title='Keep working hard '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/keep-working-hard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swing JTable</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/swing-jtable/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=swing-jtable</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/swing-jtable/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 08:15:25 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=59</guid>
		<description><![CDATA[Some links about Swing JTable, and TableModel<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/swing-jtable/' addthis:title='Swing JTable '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>I've been working hard these days, and I almost have an usable version of PennyBank. Right now, users are able to create and delete users and accounts, operate with those accounts (deposit, withdraw and transfer), displaying account operations, and importing movements from <a title="Cashbox" href="http://www.fadingred.com/cashbox/" target="_blank">Cashbox</a> PList files.</p>
<p>I will provide with some screen-shots as soon as possible, but today I wanted to talk about Swing <a title="How to Use JTables" href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html" target="_blank">JTables</a> and their <a title="Creating a Table Model" href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#data" target="_blank">TableModel</a> property. Tables are great tools when you need to display a collection of data, so you can arrange it in rows (one row per element in the collection) and columns (one column per attribute in the element).</p>
<p>JTables are quite easy to use. You need to declare the table itself, give it a model, and display it in your panel. Depending on the model you choose, you can edit the table's cells, you can display the elements according to their type...</p>
<p>Even when Sun's tutorial is nice enough to have the basic necessities solved, these three articles I found on <a title="InformIT" href="http://www.informit.com/" target="_blank">InformIT</a> are very good pointing at the changes you may probably want to do with your tables:</p>
<ul>
<li><a title="Creating a Custom Java Swing TableModel" href="http://www.informit.com/articles/article.aspx?p=332278" target="_blank">Creating a Custom Java Swing TableModel</a></li>
<li><a title="Building a Profesional Swing JTable" href="http://www.informit.com/articles/article.aspx?p=333472" target="_blank">Building a Professional Swing JTable</a></li>
<li><a title="Sortable Swing JTable" href="http://www.informit.com/articles/article.aspx?p=337310" target="_blank">Sortable Swing JTable</a></li>
</ul>
<p>Now, I still have to give my table the OS X standard Look &amp; Feel, painting even and odd rows with different colors each one. <a title="How to add zebra background stripes to a JTable" href="http://nadeausoftware.com/articles/2008/01/java_tip_how_add_zebra_background_stripes_jtable" target="_blank">This link</a> provides some good steps to accomplish that task.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/swing-jtable/' addthis:title='Swing JTable '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/swing-jtable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some (unasked) explanations</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/some-unasked-explanations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=some-unasked-explanations</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/some-unasked-explanations/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 00:11:42 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=52</guid>
		<description><![CDATA[In occasions, the amount of time spent actually developing an application is less than the time spent thinking how to do it.<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/some-unasked-explanations/' addthis:title='Some (unasked) explanations '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>When I started  developing PennyBank, the first decision I faced was the programming language I should use. I wanted something that looked integrated in the system, like iTunes, Mail, iCal... The first choice was obviously  <a title="Objective-C" href="http://en.wikipedia.org/wiki/Objective-C" target="_blank">Objective-C</a>, with the interface done in <a title="Interface Builder" href="http://developer.apple.com/tools/interfacebuilder.html" target="_blank">Interface Builder</a>. I had followed a small tutorial, and doing a trivial application (a calculator, I think) had showed me how good its visual programming was.</p>
<p>In my job I work using <a title="C# Programming Language" href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)" target="_blank">C#</a> with <a title="Visual Studio" href="http://msdn.microsoft.com/en-us/vstudio/default.aspx" target="_blank">Visual Studio 2008</a>. I can develop <a title="Graphical user interface" href="http://en.wikipedia.org/wiki/Graphical_user_interface" target="_blank">GUIs</a> real quickly, without having to withdraw time from what it is usually more important: the business logic. Here, I wanted more or less the same. I wanted a language which could let me focus on the logic without too many headaches when doing the GUI. So Objective-C seemed the right option, as there was that Interface Builder tool. But after just some searches in Google, I realized that I wouldn't be able to get the application done if I chose a language I was not familiar with.</p>
<p>And so I chose Java. I've done many small apps in Java when I was studying, so I feel quite familiar with it. Besides, I wanted to try <a title="Hibernate" href="http://www.hibernate.org/" target="_blank">Hibernate</a>, so this seemed a very good excuse. The other reason to choose Java was SWT. Some friends and I developed an application last year using <a title="The Standard Widget Tool" href="http://www.eclipse.org/swt/" target="_blank">SWT</a>. We were targeting Windows, but I recall reading that SWT was "the ultimate Java interface" in terms of native <a title="Look and feel" href="http://en.wikipedia.org/wiki/Look_and_feel" target="_blank">Look &amp; Feel</a> integration. As our application got to look great in Windows, I started coding in Java with the idea that SWT would save all my problems.</p>
<p>I was wrong. After two weeks developing the model layer with Hibernate, I wrote the first lines of code for the GUI. It was quite strange: I needed several days to notice that something was going wrong. The first days it was due to the following: <em> </em></p>
<blockquote><p><em>The special VM option     <strong><tt>-XstartOnFirstThread</tt></strong> is also required for SWT applications     to run properly on the Mac.</em></p></blockquote>
<p>It is stated clearly in the <a title="Deploying SWT Applications on Mac OS X" href="http://www.eclipse.org/swt/macosx/" target="_blank">Mac OS X section</a> of their page, but somehow I didn't read it, experiencing some real awful exceptions until I found it. After that, I had several issues that almost have PennyBank development stopped. First of all was the lack of a good Visual Editor in Eclipse. OK, there was the <a title="Visual Editor plug-in" href="http://www.eclipse.org/vep/WebContent/main.php" target="_blank">Visual Editor plug-in</a> , but I wasn't able to get it working:  its support seemed to have been dropped off, and there was no sign of activity in its section for the last two years (Jump <a href="#veplugin">here</a> if you don't want to read the rest and want to find which solution I found). After that, I wrote the first example of a toolbar.</p>
<p>It was... weird. I was looking at the main window, knowing that something wasn't right, but unable to tell what it was. The toolbar! This was NOT an OS X toolbar!After that, I knew that I had no reason to keep using SWT, as it wasn't giving me the integration I was expecting, nor it was giving me any ease of visual programming. I found a blog where someone built an  <a title="Making SWT look more native on Mac OS" href="http://blog.laurentm.com/2008/07/making-swt-look-more-native-on-mac-os/">unified tool bar using SWT</a>, but it looked too much of a hacking for me. So I moved to <a title="Netbeans" href="http://www.netbeans.org/" target="_blank">Netbeans</a>: I knew it had a <a title="Matisse on Netbeans" href="http://www.netbeans.org/kb/trails/matisse.html" target="_blank">tool for writing GUIs</a> so even if I would be coding a <em>not-so-nice</em> application, at least it would be faster.</p>
<p>Using <a title="Maven" href="http://maven.apache.org/" target="_blank">Maven</a> proved here to be a very wise decision: migrating from an IDE to the other was painless. But I didn't stay with Netbeans too much: after an strange problem with Subversion, I moved back to <a title="Eclipse" href="http://www.eclipse.org/" target="_blank">Eclipse</a>. At the beginning, I even thought about developing the interface by hand. Fortunately, I found a better solution.</p>
<p><a name="veplugin"></a>Even if the plug-in was officially unsupported, in <a title="Visual Editor plug-in" href="http://wiki.eclipse.org/VE/Update" target="_blank">this page</a> a link is provided to have it working under the last Eclipse build. Now that I was able to do visual programming, the only point missing was the so much wanted operative system integration.</p>
<p>So I started searching for <em>"Java OS X integration"</em>, finding lots of resources... until I found The One. <a title="Exploding Pixels" href="http://explodingpixels.wordpress.com/" target="_blank">Exploding Pixels</a> writer has developed <a title="Mac Widgets for Java" href="http://code.google.com/p/macwidgets/" target="_blank">Mac Widgets for Java</a>: some great widgets which gives the application a native look and feel. Another <em>must have</em> link is the <a title="Java Development Guide for Mac OS X" href="http://developer.apple.com/documentation/Java/Conceptual/Java14Development/index.html" target="_blank">Java Development Guide for Mac OS X</a>. With this one and the <a title="Apple Human Interface Guidelines" href="http://developer.apple.com/documentation/userexperience/Conceptual/AppleHIGuidelines/index.html" target="_blank">Apple Human Interface Guidelines</a> I think I have all the technical information I need.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/some-unasked-explanations/' addthis:title='Some (unasked) explanations '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/some-unasked-explanations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Misunderstanding Hibernate</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/misunderstanding-hibernate/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=misunderstanding-hibernate</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/misunderstanding-hibernate/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 18:30:40 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[CascadeType]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=45</guid>
		<description><![CDATA[After some more tests, I've found that I was wrong with some ideas I had about Hibernate.<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/misunderstanding-hibernate/' addthis:title='Misunderstanding Hibernate '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>These last days I've been doing more <strong>JUnit</strong> tests. And thanks to them, I've discovered some serious misunderstanding I had about <strong>Hibernate</strong>, <strong>Cascading</strong> (yes, again) and <strong>ManyToOne</strong>, <strong>OneToMany</strong> relationships.</p>
<p>The first mistake I have was start coding too fast. I started following a tutorial, but I confess that I focused too much on code, an little on the theory. Following that tutorial I set a <strong>OneToMany</strong> relationship between an <em>user</em> and his <em>accounts</em>. Somehow, I thought that the <em>account</em> list in the <em>user</em> side would get filled <a title="automagically - Wiktionary" href="http://en.wiktionary.org/wiki/automagically" target="_blank">automagically</a>, driven by the annotations I was using. As the accounts got dropped from the database when I deleted an user, I thought everything was alright, and I didn't think about too much.</p>
<p>Yesterday, doing some tests on the <em>category</em> entity, I found that in a child-parent relationship, the child didn't have its parent <em>category</em> updated when I deleted that parent <em>category</em>. In the database I had set <strong>"ON DELETE SET NULL"</strong>, and looking at the database while performing the tests showed that it was working there. But <strong>Hibernate</strong> didn't seem aware of that behavior, and the link to the old parent <em>category</em> still appeared in the child. That led me, after some tries, to understand how cascading was supposed to work and how badly I was using it. I had several cascading annotations in the <strong>ManyToOne</strong> side of some relationships, which meant that when I made a change on the <em>many</em> side, the other side was getting affected. And that wasn't the behavior I was expecting!</p>
<p>I went to the documentation to learn how should annotations work, and what did they mean according to the context they were used in. After that, I removed most of my annotations, and made some changes, in the <em>update</em> and <em>delete</em> methods in my <em>DAOs</em> to spread the changes when that was needed.</p>
<p>Now, an <em>user</em> has a list of <em>accounts</em>. When an <em>account</em> is created, it sets a reference to the <em>user</em> who has it. And makes that <em>user</em> add it to his <em>account</em> list. When an <em>account</em> is deleted, it makes the <em>user</em> remove it from the <em>account</em> list. As the <em>account</em> <em>operations</em> have a reference to an <em>account</em>, <strong>Hibernate</strong> is responsible to update that reference.</p>
<p>The <em>categories</em> behavior is similar. When a root <em>category</em> is created, it creates an empty list of child <em>categories</em>. When you add a child <em>category</em> to a parent <em>category</em>, you add that child to his parent list. When deleting the parent, you have to go through the list, updating all the references in his children. When deleting a child, you have to remove it from his parent list.</p>
<p>After these changes, everything is working now. I know that some of the tests I've done are too bound to my interpretation of the behavior they have to show, and so they may be wrong. But at least I get rid of part of the errors I still have.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/misunderstanding-hibernate/' addthis:title='Misunderstanding Hibernate '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/misunderstanding-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate common errors</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hibernate-common-errors</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 22:43:26 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[deleted entity passed to persist]]></category>
		<category><![CDATA[detached entity passed to persist]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[id to load is required for loading]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=43</guid>
		<description><![CDATA[A better explanation about some usual Hibernate-related errors: deleted entity passed to persist, detached entity passed to persist and id to load is required for loading<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/' addthis:title='Hibernate common errors '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Just two days after I <a title="Mind the Cascade" href="http://www.simonpena.com/blog/proyectos/pennybank/mind-the-cascade" target="_blank">blogged</a> <a title="Testing..." href="http://www.simonpena.com/blog/proyectos/pennybank/testing" target="_blank">about</a> the errors <strong>deleted entity passed to persist</strong>, <strong>detached entity passed to persist</strong> and <strong>id to load is required for loading</strong>, some people came here from web searches.</p>
<p>As I'm not sure if those explanations were clear enough, I'll try to synthesise here:</p>
<ul>
<li><strong>Deleted entity passed to persist</strong>. One entity, supposed to be deleted, is still referenced / accessed. In my case, I had a problem with "<em>cascading</em>". The behavior I expected was "<strong>on delete cascade</strong>" and "<strong>on update cascade</strong>". I have those constraints well in the database, but they weren't right in the Hibernate annotations. After I changed that, the error stopped. While I was searching why I was getting this error, I've seen people whose problem was different. They had, let's say, a list of entities. Those entities were related to others, and, when deleting, they had to take care of deleting both the link and the persisted entity. This was the most common scenario of this problem, and is better explained <a title="Ejb3 Tutorial 3 - Finish Conversion" href="http://schuchert.wikispaces.com/Ejb3+Tutorial+3+-+Finish+Conversion" target="_blank">here</a>, for example.</li>
<li><strong>Detached entity passed to persist</strong>. One entity, which is supposed to be up to date but is not, is passed to persist. In my case, I was trying to create an entity (an Operation), related to another (the Account where that Operation was taking place). The persist action was failing because my version of the Account was incorrect. The solution was just to update the entity.</li>
<li><strong>Id to load is required for loading</strong>. Trying to access an entity without giving an actual identifier. In my case this was the easiest problem: I was calling <em>find</em> passing a non initialized long. Passing the correct, initialized values fixed the problem.</li>
</ul>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/' addthis:title='Hibernate common errors '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Testing&#8230;</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/testing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=testing</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/testing/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 05:12:12 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[id to load is required for loading]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=40</guid>
		<description><![CDATA[Some more JUnit test cases, and some more actions implemented. The application keeps growing.<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/testing/' addthis:title='Testing&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Today I spent all the afternoon testing. It may seem a tedious task, but after a while it gets quite challenging: you know there are errors in your code, so the objective is finding them. And while doing those tests, correcting the actions which showed wrong, I implemented some new ones.</p>
<p>The application is getting closer and closer to an usable state, and I expect it to be running in about two or three weeks.</p>
<p>Today's odd error was a lot easier than the others: <strong>id to load is required for loading</strong>. Maybe not the most complete description, before you find the place it is failing, but good enough once you go to the correct line number. I was using some fields in an Action which I haven't initialized yet. D'oh!</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/testing/' addthis:title='Testing&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mind the Cascade</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mind-the-cascade</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 03:33:00 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[CascadeType]]></category>
		<category><![CDATA[deleted entity passed to persist]]></category>
		<category><![CDATA[detached entity passed to persist]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=28</guid>
		<description><![CDATA[Refactoring JUnit tests and changing the way account operations are organized has revealed some bad annotations.<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/' addthis:title='Mind the Cascade '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Today I decided to go through the model layer, implementing as many <a title="JUnit.org" href="http://www.junit.org/" target="_blank">JUnit</a> tests as I could, and completing all the actions I hadn't implemented yet. As I said <a title="Classifying account operations" href="http://www.simonpena.com/blog/proyectos/pennybank/classifying-account-operations" target="_blank">before</a>, I had just decided to stick to <em>one-category-at-a-time </em>scheme, having a hierarchical relationship between categories.</p>
<p>I thought it would be easy: change the Category entity, check the <em>on delete </em>and <em>on update </em>constraints in the database creation script, refactor and go on.I also had in mind some refactor in my JUnit tests: I have just two cases, one for each Facade, and several methods inside, for each of the actions in that facade. But as the application was getting larger and larger, I decided to have one JUnit case for each Facade Method, with several test methods for each of the possible scenarios I can think of.</p>
<p>So I was there, refactoring tests, moving some code to the <a title="@BeforeClass annotation" href="http://junit.org/apidocs/org/junit/BeforeClass.html" target="_blank"><em>setUpBeforeClass</em></a> and <a title="@AfterClass annotation" href="http://junit.org/apidocs/org/junit/AfterClass.html" target="_blank"><em>tearDownAfterClass</em></a> methods, when everything started to break:</p>
<p><strong>deleted entity passed to persist</strong> and <strong>detached entity passed to persist</strong>. After some research in Google, I understood what could be causing the second error, so I solved it:</p>
<p>I was using an entity in a call to persist which had been "left" unchecked by the entity manager  (detached is the word, but I didn't know it). I got the entity again by invoking <em>find</em>, and passed it fresh, and it worked out.</p>
<p>But the first problem was harder. Google didn't shed any light on me (apparently), as everything was about deleted entities which were still referenced by others related to them. I didn't have any entity left: this was happening in the <em>tearDownAfterClass</em> method, and I was removing the entities left after the test. And then I realized that most of the clean up was supposed to be done by cascading. So, maybe <a title="CascadeType (JAVA EE 5)" href="http://java.sun.com/javaee/5/docs/api/javax/persistence/CascadeType.html" target="_blank">cascading</a> tags were incorrect. I checked out my classes, and I changed some of them: putting the explicit ones instead of <strong>CascadeType.ALL</strong>. I still have to test some of the <em>Update</em> methods, but for today, it's fixed.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/' addthis:title='Mind the Cascade '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Classifying account operations</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/classifying-account-operations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=classifying-account-operations</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/classifying-account-operations/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 23:06:20 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[classifying]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[operations]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=22</guid>
		<description><![CDATA[Some thoughts about how to classify the account operations, keeping the code simple enough, but without taking any flexibility from the user<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/classifying-account-operations/' addthis:title='Classifying account operations '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>One of the things that made me start coding PennyBank was the idea of classifying account operations in various ways. I first thought about using categories, and letting the user add several ones to an account operation. That could be quite flexible, but after some time thinking, I realized that an account operation is most times classified in just one category: another question is if that category is a subcategory of another one more general.(If I buy a video game, this could be classified in the <em>"video games"</em> category, in the <em>electronic</em> category or even in a more general <em>"spare time"</em>. But it appears to me that there is a hierarchy relationship between those categories )</p>
<p>Having just one category  looked enough for me, until I realized that sometimes you may want to highlight, someway, an operation. And that could be done using <em>tags</em>. They should be different from categories, being a more specific way to filter operations, but making easier to develop the application core.</p>
<p>So, right now, this is the selected choice. One operation could be categorized or not, but should be classified in just one category. Categories, themselves, can be arranged hierarchically. And finally, operations can be tagged with multiple tags.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/classifying-account-operations/' addthis:title='Classifying account operations '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/classifying-account-operations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

