keyboardsamurais.de thoughts on software development, warts and all…

16May/071

Pain is the cost of Spring MVC’s elegance

I'm surprised about how far Spring has come without ever adressing simple everyday problems. If you really, honestly want to use Spring for your application all the way through, be prepared for some good shockers. Want some spring oddities?

Lets start with a question, what do you think caused this exception?

Now, you may come to the conclusion that
a.) Jetty has had a problem in transferring some streams back and forth
d.) The Hibernate Session may have been closed
c.) Space aliens hijacked your VM

...but, no - that all didn't happen. It was just the Spring way of telling me: Your Hibernate mapping needs some lazy loading if you're gonna mess around with circular dependencies. Nice one. Even better that the OpenSessionInViewFilter covered up the original error message that could've been actually helpful. Just adding @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL,mappedBy="user") helped me though. The time it took me to figure this out, would've bought me many a meal, had I only opted to spend it on real work.

But on to the next one: the Spring taglib. Whether you want to use the old tags or the new form:* tags that spring offers you, you will have to specify a commandName. That wouldn't be so bad if it wasn't for the fact that the tags will just flip out and throw one hell of an Exception, if you fail to have an actual instance of the command that is being referenced in your Model. This means if you want to embed a login form on every page you use, you will have to make sure, that every single Controller for every single page adds a blank LoginCommand class to your Model. Note that the form:* tag is Spring's the second take on tackling the problem of creating a usable taglib. Why Rob Harrop and Juergen Hoeller, the two (usually brilliant) guys who are to blame for this abomination, don't just crawl into a cave and cry, because of the shame they brought on themselves, is a mystery that boggles the mind. Why not just let the poor tag fail silently, like in EL? We may never know, what drugs were at play during design.

You think I'm joking? It gets better. Since the SimpleFormController allows only support for exactly one type of form-backing command, you will have to deal with multiple commands yourself - manually, or use a command that has nested properties - *yay*. What this means is, adding every command to the page with multiple forms, so those form:* tags don't detonate in your face. The SimpleFormController really isn't of much help here. Instead you have to mess around violently in xml hell, or abuse springs design principles to get what you need. That is, unless you take the time to bring the old MSPC modules, whose sf.net page looks pretty dead to me, up to date. This is a problem the Spring community has been struggling with for YEARS. I cannot possibly understand how it can be so hard to create something nice here. I am constantly tempted at writing my own spring extensions.

I had to vent. Overall Spring MVC isn't that bad - there are just some parts of it, you better just don't touch, lest you want to suffer a heart attack.

Update: Found a cumbersome workaround for the taglib issue.

Filed under: Coding Leave a comment
Comments (1) Trackbacks (0)
  1. Yep I couldn’t agree with you more. I’ve been using Spring together with Hibernate for over a year now, and if I had known then what I know now.

    I’ve learned a lot from Spring, but it’s insane how much time I’ve spent tracking down even the simplest of bugs.


Leave a comment

(required)

No trackbacks yet.

Bad Behavior has blocked 729 access attempts in the last 7 days.

FireStats iconPowered by FireStats