Skip to content

In which magic method naming is considered to be harmful

AKA EJB <= 2.x Entities are a stupid idea stupidly implemented.

A blast from the past. What idiot decided this was a good idea?

public interface SomeEntity {
    String getType();
    String getName();
}
 
public interface SomeEntityHome extends EntityHome {
    SomeEntity findBySomeData(String name, String type);
}
 
public class SomeEntityEjb implements SomeEntity, EntityBean {
    public SomeEntity ejbFindBySomeData(String name, String type) {
        // some cogent implementation here
    }
    public String getType() {
        return this.type;
    }
    public String getName() {
        return this.name;
    }
}

Let’s refactor SomeEntityEjb.java shall we? Change that ejbFind method. Then spend the next half hour figuring out what you did wrong – Jboss doesn’t deploy the EJBs! Grep the code-base for “ejbFindBySomeData” … there’s got to be a magic specification of that method somewhere in the code. Nothing found?!  Hmm it’s been years since I’ve dealt with < 3.0 Entity Beans. Struggle to recall the EJB specification .. what are the magical matching methods in the Home interface? Oh yeah, that’s right!  EntityHome has findXXX, EntityBean has ejbFindXXX. Why, in god’s name, why?

No wonder people got dead-set against EJBs (meaning Entity EJBs) back in 2001 or 2002. Ahhh give me Spring and Hibernate anyday. And remember - parallel magic method naming is a stupid idea – especially in a statically typed language that is supposed to let the compiler do the hard work for you. Jesus kill the people who invented this. Please.

I wish I had the scope just to remove all these Entities …