All entries for November 2005

November 30, 2005

Some more hibernate fun :)

So I was debugging a problem with some code and I discovered this little gem:

Assume you have the following hierarchy:

– ClassInterface (use as proxy in mapping files)

– AbstractClass implements ClassInterface (used as the persistent class)

– ClassImpl extends AbstractClass (mapped as subclass of AbstractClass)

Load an instance of ClassImpl ala "ClassImpl ci = (ClassImpl)session.load(AbstractClass.class, someId)"

Now if you are going to compare two instances (using hashCode/equals) then guess what; if you implement that logic in ClassImpl it won't work. You must implement that logic in the abstract class that you have specified in the mapping file.

This is all to do with the joy that is cglib; even though the instance you are loading will eventually be a ClassImpl (based on the discriminator) CGLIB claims not to know that until it is fully initialised :(

OK, what happens if you try and load an instance of ClassImpl? Same thing. The equals method AbstractClass is used.

I have also run into situations with hibernate where code works if you step through, but not if you run it without debugging. I can only think that stepping through is maybe causing toString to initialise the object properly, hence subclass logic is utilised, but I cannot reproduce it.

Lame. Understandable, but lame.

To be fair; hibernate is great. It rocks, but it is not transparent* :)

November 29, 2005

Refigerator code. Nice.

Writing about web page

Learned a new phrase today :)

Yeah; another buzz-word that I can use to confuse co-workers and pretend I am more intelligent than they are!

November 22, 2005

Excellent spring related web site

Writing about web page


spring container + inner beans

Writing about web page

So I recently had to wire up some spring managed beans with some constants. ….and I hadn't the foggiest on how to do it :)

Perusing the forums and the spring documentation, I found this little beauty

The problem is that you are not creating a new instance of the constant, you are merely referencing that constant, so the usual
<bean id="uk.yourcompany.class.CONSTANT"/>
wouldn't work because you are asking spring to instantiate a new instance. You must do
<bean id="uk.yourcompany.class.CONSTANT" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>

To reference it, simply do

<bean id="yourBean" class="uk.yourcompany.class.SomeBean">

On a related note, if you do want to instantiate an inner class (so long as it is public), you cannot do

<bean id="yourBean" class="uk.yourcompany.class.OuterClass.InnerClass"/>

you must do

>bean id="yourBean" class="uk.yourcompany.class.OuterClass$InnerClass"/>


November 11, 2005

Quick speed up for JBOSS

Writing about web page

Very useful, although loosing all that debugging info makes me a little nervous ;)

November 10, 2005

How much can a wooden shelf hold?

Hi all you clever structural engineering types :)

I have a 3.5ft recess into which I plan to put a shelf that will have to hold 200kg.

The shelf will be supported on three sides by a brick fireplace, a weight-bearing wall between me and the neighbours (long), and an external, weight-bearing wall.

It has to be attached to the wall, but how? Will 3×3" battons with 6" screws be sufficient, or should I look at some metal braces?

Please help :) I cannot seem to find anywhere that can tell me how to do this :(

P.S. It will be holding a fish tank, beneath it is another fish tank+sump on their own cabinet so it really cannot break :)

November 09, 2005

Crappy serialization :(

So I want to serialize an object which has a collaborator, i.e.:

  class MyClass {
    private final Collaborator collaborator;

    public MyClass(final Collaborator theCollaborator) {
      this.collaborator = theCollaborator;

Unfortunately MyClass needs to be serialized, but the Collaborator cannot be, so what do you think would happen if MyClass was changed:

  class MyClass {
    private final transient Collaborator collaborator;

    public MyClass(final Collaborator theCollaborator) {
      this.collaborator = theCollaborator;

OK, everything works, but as expected (despite the "final" keyword :)) the collaborator was null.

So what about:

  class MyClass {
    private final transient Collaborator collaborator = new SomeImplementationOfCollaborator();

Well I initially expected it to instantiate a new collaborator when deserializing, but no. It doesn't. It leaves it null.

Why doesn't it do it? Maybe because it might be serialized in an environment where SomeImplementationOfCollaborator cannot be found. Well surely throwing a ClassNotFoundException would be the right thing to do?

The really stupid thing is that this works:

  class MyClass {
    private static final transient Collaborator COLLABORATOR = new SomeImplementationOfCollaborator();

Go figure :)

Bah humbug.

P.S. Yes, I am sure if I read the appropriate bot in the java spec it would be absolutely clear and there is surely some really obvious reason. But why should I? (yeah, OK, maybe I should :))

Very funny :)


A graceful taunt is worth a thousand insults.
– Louis Nizer

I feel so miserable without you, it's almost like having you here.
-Stephen Bishop

He is a self-made man & worships his creator.
– John Bright

He has all the virtues I dislike and none of the vices I admire.
– Winston Churchill

A modest little person, with much to be modest about.
– Winston Churchill

He has sat on the fence so long that the iron has entered his soul.
– David Lloyd George

Thank you for sending me a copy of your book; I'll waste no time reading it.
– Moses Hadas

He is not only dull himself, he is the cause of dullness in others.
– Samuel Johnson

He had delusions of adequacy.
– Walter Kerr

He can compress the most words into the smallest idea of any man I know.
– Abraham Lincoln

You've got the brain of a four-year-old boy, and I bet he was glad to get rid of it.
– Groucho Marx

I've had a perfectly wonderful evening. But this wasn't it.
– Groucho Marx

Some cause happiness wherever they go; others whenever they go.
– Oscar Wilde

He uses statistics as a drunken man uses lamp-posts…for support rather than illumination.
– Andrew Lang

Your manuscript is both good and original; but the part that is good is not original, and the part that is original is not good.
– Samuel Johnson

Better a witty fool than a foolish wit.
– Shakespeare

November 08, 2005

Looks promising

Writing about web page

This looks like a very interesting article. Haven't read it yet, so this is just a reminder for me to read it, but it looks like it deals with a very interesting subject matter; unit testing aspects.

November 2005

Mo Tu We Th Fr Sa Su
Oct |  Today  | Dec
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30            

Search this blog



Most recent comments

  • Interesting… While I'm not completely convinced in such microbenchmarks, I'm pretty sure that 1ms … by Alexander Snaps on this entry
  • Hello. I bought the book yesterday. I was trying to find the source code for chapter 11 and chapter … by Suleman on this entry
  • by live mashup demo on this entry
  • Thanks mate ….. This blog was really helpful. by Maaz Hurzuk on this entry
  • Ty. Not directly helpful for my problem, but pointed me in the right direction. You will also get th… by Mike E. on this entry

Blog archive

Not signed in
Sign in

Powered by BlogBuilder