Rainy days and Java always get me down

I've Moved My Blog

It's currently located at http://www.urlinone.com/blog

I should say "I'm moving my blog." It's a pretty painful process.

Pebble has blown up on me, and it's been many months since I've been able to blog reliably. I've lost posts. And now I've got to figure out how to migrate my past blog posts from Pebble to my new destination without all the URLs changing, lest external links become 404 Not Founds.

Why does everything in the 21st century have to be a three-day project???

Matt Raible has changed BaseObject in the upcoming version of AppFuse so that equals() and hashCode() are abstract, meaning that all your AppFuse model classes will have to implement these methods. Matt suggests using Commonclipse to automatically generate these methods. It certainly beats creating them all by hand!

It's easy enough to add Commonclipse to Eclipse 3 by doing Help > Software Updates > Find and Install > Search for new features to install > Next > New Remote Site. Put Commonclipse in the Name and http://commonclipse.sourceforge.net in the URL. Click OK. Click Next.

Once Commonclipse is installed and Eclipse has restarted, do the following to get it working for AppFuse:

Window > Preferences > Java > Commonclipse. Select the General tab. Uncheck the second and third checkboxes, which are to Append super in hashCode() and Append super in equals(). Click Apply (if you like) and OK.

The body of BaseObject in AppFuse 1.5 contains actual implementations. To delegate these methods to their subclasses, change BaseObject and the methods to abstract, as in the following:

public abstract class BaseObject implements Serializable {
    public abstract String toString();
    public abstract boolean equals(Object o);
    public abstract int hashCode();

Now you are ready to use Commonclipse to generate the implementations for these abstract methods in your model classes. In Eclipse, open each class that is derived from BaseObject. You can have Eclipse find them all for you by clicking on the word BaseObject in the editor window and hitting the F4 key. This will open the Hierarchy view and show you all the classes that have BaseObject as a superclass.

Open each class by double-clicking it in the Hierarchy window. In the editor, right-click, go down to the Commonclipse menu item, and select the method you want generated. Unfortunately, Commonclipse makes you repeat this task for each method, and I am not aware of a keyboard shortcut, although I longed for one.

Take note of two quirks I came across with Commonclipse

  1. A couple of times, it actually modified BaseObject, rather than the class I was editing.
  2. More frequently, it would not do anything after I selected the generate menu item. There was no error message, but the method was not generated.

I think both these problems might have something to do with focus of the editor window. I think the key is to left-click in the editor window to ensure that the file you can see is also the one that has focus. (Make sure the insertion point in the editor window is flashing.) One thing I noticed is that you can single-click a class in the Hierarchy window, if the file is already open in the editor. When you do that, the editor window for that file comes to the front, but the focus is actually still in the Hierarchy window.

I'm not positive that's the root cause of the problem, but closing and reopening the file and doing any kind of editing in the file seemed to get past the do-nothing generate task.

Do you happen to know what is the reason to remove these method implementation from BaseObject? Thanks! ct
I know theres some issues with Hibernate, hashCode and many to one relationships. I don't remember what it was, but I came across it a few months ago.
I too remember issues with hibernate and hashcode. My main question though, is, why did you(or Matt) make BaseObject a class rather than an interface??
Oh forget my previous question, i just realized why.
just a note from the commonclipse author: <br> you can select all your java classes in package explorer and generate the required methods for all of them in one shot ;) <br> <br> http://commonclipse.sourceforge.net/screenshots.html
Why isn't BaseObject an interface? And isn't the whole idea of a 'BaseObject' a bit intrusive?
I tried the plugin, but it deson't work in eclipse 3.0.1, is there any other plugin which can do the same thing?
you can use is Commons4E but I havan't used it .It's don't worked in my eclipse
Doesn't work with eclipse 3.02 The option shows up in the explorer but when you select Commonclipse and click on any of the selection (eg: generate toString() etc.. nothing happen...
Pascal, it likely doesn't work because you installed the wrong version. If you are running eclipse 3.02, be sure to install commonclipse 1.2.0
I just tried using Commonclipse and found that it's generating the toString, hashCode and equals methods using a super.xxx method -- which javac doesn't like because the source code is trying to directly access an abstract method...
And then I demonstrated my inability to read carefully where this very page tells me exactly how to avoid that problem. Sorry.
Matt will please explain why Base Object is not an interface but abstract
Whatch out when using commonclipse when you have redundant relationships in your classes. Chances are that you will end up in an endless loop when calling one of the generated methods. /Tony

Add a comment

HTML : b, i, blockquote, br, p, pre, a href="", ul, ol, li
E-mail address
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).

TrackBack to http://www.leegrey.com/hmm/addTrackBack.action?entry=1096491256000