« TSS Java Symposium Barcelona | Main | Off to Eclipse Summit Europe »

An Infestation of Snails (was: Java Annotation Madness)

I was just reading an article on JPA, posted on TheServerSide. In it we see a simple 'real-world' example - a mocked-up blog application. The object model looked fine, the DB schema representation looked fine, but then I got to see the Java, annotated JPA-stylee.

import javax.persistence.*;

@MappedSuperclass
@EntityListeners({ModelListener.class})
public abstract class ModelBase {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id")
    private Long id;
    @Version
    @Column(name="version")
    private Integer version;
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="created_by_user_id")
    private User createdByUser;
    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "date_created", nullable = false)
    private Date dateCreated;
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="updated_by_user_id")
    private User updatedByUser;
    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "date_updated", nullable = false)
    private Date dateUpdated;
    // methods removed for readability
}

I got a bit of a chuckle out of the comment at the end of class declaration, but my overall feeling was one of giddiness at the sight of Annotations Gone Mad. It's fashionable, it appears, to bang in as many annotations as possible in Java 'frameworks'. If you have dealt with debugging C# webservices clients, you might recall the brain damage that was introduced when trying to fish through dozens of C# annotations in the generated code. Is this going to happen all over again, but for Java this time?

My particular complaint is not about using annotations, which I do think are wickedly useful for getting rid of the omnipresent and immiscible configuration APIs in thousands of products. Being able to inject values into class members is brilliant. There are even some gnarly uses where annotation declarations may themselves have annotations (go look at the Apache Camel source code). But using annotations to tie Java programs to what are irreducible and unmappable resources - ports, URLs, even DB tables - doesn't make a lick of sense to me.

Update: Benson Margulies has given this condition a name - an infestation of snails (@) - in a cxf-dev posting. This is so good I had to change the name of this entry.

TrackBack

TrackBack URL for this entry:
http://blogs.iona.com/cgi-bin/mt/mt-tb.cgi/526

Comments (1)

Yikes, this really reminds me of how much Java code sucks by not having frameworks that do decent 'convention over configuration' (COC)...

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on September 19, 2007 11:55 AM.

The previous post in this blog was TSS Java Symposium Barcelona.

The next post in this blog is Off to Eclipse Summit Europe.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.31