Java

ORM is evil

Object relational mapping (ORM) is evil because it is the great big programmer hammer driving the square peg into the relational data round hole. ORM is a self-fulfilling prophecy; because it treats the RDBMS as a big dumb datasource then in fact it makes the database a big dumb datasource. Worse, it allows people to not think of database as being a collection of, y’know, relational data but instead as being a list of entities. That’s true if you are using an OODBMS but ORM doesn’t mean the same thing. ORM makes your RDBMS look a bit like an OODBMS by making the data model teh suck.

The biggest problem with programmers seeing the database through the ORM reality-distortion filter is that they start thinking that the entities they deal with are the data. In most cases that simply isn’t true, or if it is it is because the entities have started to become some kind of uber-object that contains everything about everything. The kind of object in fact that made people say EJB is slow.

If you take something like a sale in an online shop that sale means different things to different people. To the accountant it means margin, to the sales referrer it means commission and to the dispatcher it means a weight, volume and address, to the customer its just a credit card charge and a wheelbarrow (or whatever it is they’ve bought).

The amazing thing about about the RDBMS is that recognises this multi-faceted view of data and accurately decomposes it into the constituent elements. The dispatcher doesn’t have to see the sales commission, the accountant doesn’t have to see the item volume. You use queries to constitute a coherent and logical projection of the underlying data that can be defined by the purpose the data is going to be used for.

ORM fanatics rarely see things this way; instead they want to denormalise here and there, aggregate bits of data directly into the record, add a few nullable columns into the schema because, hey, the Java fields can be null. In short they want to make the schema reflect their view of the world. Because they don’t have to make sure that the various departments get their reports or that auditors have their clear and independent trail they tend to see themselves as the centre of the universe and whatever hellspawned application they are working on as the answer to all the “problems” in the big dumb datastores.

A lot of people complain if you propose splitting logic between layers. The trouble is that someone who bleats about splitting across layers will inevitably followup their complaint with the proposal that all the logic should, in fact, shock horror, be located in application X, their latest wonder-project.

This proposal never works and for one simple reason, if you don’t want to split logic between layers then you are committing yourself to adding every last feature of Oracle, MySql, DB2 or whatever into your application. Access control, query languages, caching, data intersections, transactions, you name it it is in the database for a reason. Unless you can reproduce these features in your application then forget about logic splitting because you should put function where it is best serviced.

ORM should see itself as just being one consumer of data and learn to play better with others. It should be about the convenience of presenting one valid method of data modelling in a form that is more familiar to programmers. It should take away any impedance due to having to comprehend the relational model (which I admit is hard) but it should leave it there and stop thinking that is the true answer to complex data issues.

Standard
Java

Deploying JBoss 4.2.2

I recently set up JBoss 4.2 on a Staging environment. The Production environment uses JBoss 4.0.3 SP1 and there was a hanging question of whether the application could be transferred to the newer series or not. The obvious advantage of the migration would be to move EJB3.

Well it took a lot of work but I am happy to say that if you have a J2EE 1.4 application you can move it to JBoss 4.2 and EJB 2 and 3 deployments all live together happily in the container.

However there is an important bit of behaviour that has changed and that is that JBoss no longer binds to all adaptors automatically. Instead it binds to localhost by default (I think). My deployment machine was a virtual server with a NAT internal IP and an external IP linked to its DNS alias. Therefore I knew I had issues with binding as in addition to the different IPs I also do not actually have any physical network I’m binding too.

However despite noting the issue in the JBoss wiki documentation I then proceeded to fluff the configuration. Despite having the web containers up and running, along with the JMX Beans I could not get my web tier to talk to my service tier. Instead I was getting obscure messages like Object not in table or a connection timeout.

What I had failed to realise from the documentation is that specifying the --host parameter to the run.sh script is not like defining the system property jboss.bind.address. Superficially they may seem the same, indeed they are so similar that you can in fact stop and start JBoss quite happily using this parameter. However your RMI connector will have be been bound to something else and therefore all RMI calls from outside the server will get routed to /dev/null (geek joke; I have no idea what happens to them but judging from the error message the JNDI lookup fails to connect to any object in the pool capable of servicing the request, the handle lookup probably returns null).

Essentially on a non-production machine you always want to pass

--host=0.0.0.0

to the start script otherwise the services will bind to different addresses and you will have erratic behaviour where connecting to your host by it’s DNS name, the localhost alias and by 127.0.0.1 will all have different results (normally only one of them will actually have the service).

The only other issue is that the AS Log4J configuration has been renamed to jboss-log4j.xml. While this causes some short term pain it was only when I read the release note that I thought: “hey it is weird that we configure all our logging via the container’s configuration file”.

Standard
Java

Spring versus Guice

I am a bit of a heretic in my frameworks in that I don’t really like Spring. I don’t like it at all, in fact. I do recognise that it does a genius bit of work in providing an Enterprise framework for Web Container based applications and that it has created a huge and much needed kick up the ass for enterprise frameworks in general but I don’t like it.

For a start I don’t really get it. As it’s grown it seems to have acquired all the traits of the J2EE frameworks it set out to replace. It has those weird sprawling configuration files, it has loads of modules that all do different things in similar ways, it has a high learning curve.

Using Guice has put all my peeves about Spring into a context. Guice is lightweight, it is written in Java, its configuration can be traced through IDE tools. It only does one thing and it does that in an intuitive and powerful way.

Spring 2.5 have been released recently with the all important Annotation support. I tried to take a look at it again but ended up huffing off once again. I am certain that my problem is documentation, almost all of it is written in the form: “Just add this to your web.xml and you’re good to go!”. Great, but I just want to try the damn thing!

The terminology is also clunky, compare Guice’s @Inject to Spring’s @Autowired. I think they do the same functional job but I don’t really know as I don’t know what Autowired is meant to mean.

Spring is so ubiquitous that I expect I will have to learn it at some point but at the moment I am happy for that moment to come to me.

Standard
Java

Guicing Struts 2

Look how deceptively easy the Guice User Manual makes adding Guice to a Struts 2 app appear. Look, it says, just add one jar and all your dependency injection needs will be meet. Of course what it fails to tell you is that in addition to adding the plugin JAR, you also need the base jar, the servlet jar and if you want it to work you need to download a fixed plugin jar. At one point it was moaning about commons-logging as well!

With all that done though, it does indeed work as advertised.

Standard
Java, Software

XWiki

I downloaded XWiki and gave the standalone application a whirl. I’m in the market for a simple wiki, I have used JSP Wiki before and it is fine but it can be a pain to setup correctly and I would also need to figure out how to secure editing offline first (as this is meant to be a public-read, private-edit wiki). My first impression is simply one of sluggish performance. It has a lot of nice features and it does arrive locked down but viewing and editing the pages is very lethargic and the Ajax is painfully slow. This could be the server but other servers are proving snappier.

Interestingly it seems to create a database in memory and import/export the data to file on startup/shutdown. I’m not sure what the advantage of that is, it seems counter-intuitive. Looking at options for a standalone database I am unsurprised to find a not saying that Hibernate does not play well with Derby. The lack of support between products built for either Derby and HSQLDB is annoying and seems unnecessary. However from past experience I know not to try and swim against the tide on this. If the developer worked exclusively on one or the other than chances are it is going to work better with the intended platform.

I also spotted a release note about a bug that requires Tomcat Security to be switched off. That doesn’t seem to be something you want to ship with. It’s not exactly the way you play with others.

Standard
Java

Build it

This is a brilliant article that I have been using all last month on my work projects and it is both immensely powerful and very practical. It has made testing much easier and saved a phenomenal amount of time. However Nat doesn’t quite explain fully why it is so brilliant. What I have found is that once I have configured a Builder then actually I tend to use the same base object with minor alterations. If I am testing a sales catalogue for example and I want to have a test chocolate bar, then chances are I actually want three or four of them, all pretty much identical except for an id code and name. Using this technique makes it a doodle to knock out several objects in as many lines.

When I started I was conscientious about trying to provide a readable and complete API, later I realised “why bother?”. You need to find some sensible defaults for the necessary fields in the object but once you have you only need to implement the API surrounding the testing you are doing. Once you realise that then you get faster again. A lot of my work involves refactoring an old application and I am constantly surprised how few fields are actually used in the various beans and value objects. Often if you supply the “key” fields (the uid and anything else unique) then nothing else matters.

Standard
Java

Upgrade everything now

Okay so having got my PC working I foolishly did two things. One I tried to resize my disk partitions (hey in 2003 10Gb was all I would ever need for the C: partition), two I tried to re-install Windows XP after a house move. I got XP to install but couldn’t find my license key. So I decided to bite the bullet and buy Vista Home Premium instead and just get everything done in one go.

So Vista arrived this morning and this evening I stuck in the USB external DVD drive I use and… heard the DVD drive grind uselessly on the DVD for a while. Quickly chucking in a normal DVD I confirmed that that wasn’t a problem and headed over to Microsoft support. In the advice about unrecognised media it mentioned checking Firmware revisions on DVD players. Well, so be it, after all the drive is a couple of years old now, and so onto the Samsung website. They have a little updater program, that only runs on Windows… so now I am going to have to take my external DVD drive into work along with the Vista disk. Try the firmware upgrade with the disk and order CD copies of Vista if it still doesn’t work. Why should I do the latter? Well because Microsoft’s site for ordering alternative media doesn’t work with Firefox.

How come some many tech problems can only be solved by having a working platform in the first place?

Standard
Java

The Agony of being a PC Home Builder

My PC did not survive my housemove. When I booted it the BIOS screamed that there was a processor fault and that the gig was up. Dismantling the motherboard revealed no obvious faults or damage with the system but there it is; the PC was not going to boot. So one postal strike and shorted order later a new Intel Dual Core and Asus P5B-Plus (Vista Edition) arrive. With the normal sense of dread associated with assembling and dissembling PCs I set to work this weekend. I marvelled at how easy the new clip together processors and heatsinks are to installed. I worried that I’d screwed the memory by accidentally installing backwards and then I screwed the assemblage back together and thumb-screwed the case into one piece. Having completed I actually thought the whole experience wasn’t so bad. Buying an expensive Coolermaster case certainly made assembly easier than it had ever been and the rest of it was mostly clipping pieces together.

So I decided to boot, first boot works okay and I get to Windows but I need to set the BIOS to it’s defaults and I can’t use any port on the back of the motherboard. So I reboot, enter setup, hit the defaults and then restart. And I get a very cryptic error message that says Intel CPU uCode error. That’s it. Apart from a message that says “F1 to resume”. When you press F1 it reboots and does the same thing. Woe begins to fill my heart and tears creep into the edges of my eyes. What the hell is this about?

Well Googling didn’t really explain much other than people who bought the Asus P5B motherboard often have this problem and it is related to the processor. Every post recommends a BIOS flash. This is a brand new motherboard, sold as being Vista compatible, with an E6550 Intel processor which is listed as being compatible with the board. Why the hell do I have to flash the BIOS just to make the damn thing work?

There is however little choice; surveying my options I can create a bootable floppy; if I had a floppy of course, or a disk drive. Thankful this being the new millennium and all motherboard manufacturers have realised that perhaps people are not stashing obsolete hardware away in case they find a manufacturer unable to ship a motherboard which allows to use one of the most standard processors to have hit the market in years. So instead you can use the USB flash drive update.

This involves: downloading the ROM image, unzipping it to your flash drive. Sticking the drive into a functioning USB port (in my case my USB bracket was fully functional), then booting. When you hear the beep press the Del key. Then hit Alt + F2 before the BIOS boot trainwrecks on the same uCode problem. With that done you should be in the EZ Update program. Select your USB drive from the DOS-like menu and select your ROM image. The application will then read and verify it and you can zap your BIOS and get on with wondering why Creative’s MediaSource software doesn’t recognise the Creative soundcard you just installed when everything else sees it just fine thank you.

As you might have guessed finding the right BIOS flashing process took some trial and error. Seriously ASUS UI guys, what was happening at the meeting where you decided that the way people should access your new “easy” flash utility would be to hit Del, followed by Alt + F2 in quick succession? All of which has to be done exactly as otherwise you have to hit the reset button and kick off the process again.

These kind of problems make you wonder why you ever bother putting together your own kit, why not just leave the agony to Dell?

Standard
Groovy, Java, Scripting

Groovy Experiences

So I tried to implement one of my little Swing Utility ideas this weekend in Groovy. I need the utility and I thought it would be good to give the scripting language a go beyond simply using it as an interactive console onto the Java SE API. This is what I have learnt so far.

Well first off having an IDE helps. I used Smultron on OSX as it is an open source editor. Usually I use Komodo Edit for scripting and man have I become lazy about closing my brackets and braces. Probably the number one issue with my syntax.

I like to have a book to hand when learning a new language and in this case I have been using Groovy In Action. It is a good book and certainly seems to fulfill the role I have when learning something new. It is concise enough to allow me to jump to a particular topic when stuck on a particular point but also seems to have been written in enough of a structured narrative to give a context to what is going on when you are more particularly stumped. I would recommend it if you are looking for something similar.

Groovy doesn’t have the easiest error messages to understand. For example this foxed me for a bit:


links.each {
link -> if(link.startId = anId) { items.add(getItemById(link.endId)) }
}

The error message is:


org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, /Users/rrees/Documents/dev/groovy/MindField.groovy: 37: expecting ')', found '=' @ line 37, column 28.
link -> if(link.startId = anId) { items.add(getItemById(link.endId)) }

However the error is that I am trying to assign a value in an illegal location. It’s that old classic of = versus ==.

When an error blows up the stack trace is huge and this can be extremely distracting when, for example, a unit test assertion is failing. Since I am on the command line at the moment this is unavoidable but it also happens on the console and rapidly you need to clear the console before the next run. I think the console should definitely collapse the stack trace so you see the Message of the exception and then expand the stack trace when you want to see it. Often the Assertion Message is all you need.

Talking of unit tests, I needed them more than normal because while Groovy is very similar to Java there are enough differences to make it important that you double-check your assumptions. Not using equals once was a bit weird for example. Also Groovy arrays seem to differ from the Collections API safe-zone. GArrays are like Lists but don’t seem to support the List interface, no isEmpty for example. list.get(0) doesn’t get you the first element, list.getAt(0) or just list[0] does. Most collection interaction seems to be modelled after Ruby in that you have to get with the closures to do stuff. For some reason I found it difficult to get what I wanted out of the closures in one pass and I tended to get something working with the unit test and then shorten the closure to something concise.

Ruby closures did not seem this hard but maybe it was because the whole language is new on me. As Groovy allows you to bring over the Java idioms you are used to perhaps there was impedance between something that felt familiar but actually required a different approach.

My closing experience was another positive, Groovy’s XML and Swing Builder objects felt incredibly powerful and easy to use. The syntax is tough to grasp but being able to play around with it in the console helped. Swing Builder in particular feels like it could be the way you should make all Java Swing apps.

Overall it is a pretty positive experience. In term of the competitors it felt much more familiar than JRuby but the result was not as neat as Jython scripts tend to feel.

Standard
Java, Software

Eclipse 3.3 Impressions

So I’ve been using Eclipse 3.3 Europa to work on OSX and Windows using Google Code as the SVN provider.  Details about the project later but for now just a few thoughts on the new release:

The Awesomes…

  • Cut and Pasting code also results in the imports being added to the destination class.
  • Refactoring is all done inline in the class editor, there’s no separate dialog unless the refactor runs into trouble
  • Drag and drop in the editor works (hallelujah!)
  • Sensible packaging strategy that seems to contain everything you need for Java development (except SVN, Subversive or Subclipse should definitely be part of the standard bundle)
  • Seems to be perfectly cross-platform (Eclipse 3.2 was a bit weird on Vista and I never really liked it on OSX)
  • Ant 1.7!

Pains in the ass…

  • It’s still a little more than flaky in its threading, auto-completion has this weird glitch where it hangs, tells you its waited too long and then when you acknowledge that dialog it actually shows you the completions. This one seems confined to Windows.
  • On OSX the JUnit Test Runner seems to start up as it’s own application. I can’t figure out what set of circumstances makes it happen (initially I thought I had clicked an option or used a weird key combo but does not seem so likely). I also had the Class Loader get in a total mess when running the Unit Tests but the two may be linked.
  • No way to quickly adjust the font size in the editor. I’ve got a big screen and that’s great for the big picture but sometimes I want to enlarge code I’m working on so I don’t have to have use ninja precision with the mouse.

Outside of these there are some grey areas, the spell checker is a good idea and god knows there are enough programmers who need it. However it is not a tremendous value add and when it goes wrong it is a memory and processor monster. At work on Vista it decided that an XML file was a text file that was entirely invalid grinding the whole machine to a halt. What I would have liked instead is a bundled Servlet Engine like Tomcat on NetBeans. I’m sure there is some plugin that will provide this but I think it should be a part of the bundle (like SVN support).

Overall though Europa is still a bit of a “is that it?” experience. I recognise that there has been a significant amount of effort and everything looks really polished now but sometimes the new features make me thing “why was I putting up with that in the first place?”. Why didn’ t drag and drop work in the Java editors? If I was doing Java Enterprise why did I have to round up and install my own plugins? Why wasn’t the Ant Plugin for Eclipse 3.2 updated as a minor release?

The Europa developers have done a great job and there is no way I would stick with Eclipse 3.2, but there’s nothing so far that blows me away here.

So, what about the big question that always brings readers to the blog? NetBeans 5.5.1 or Eclipse 3.3? Well 3.3 does make some of NetBeans features look distinctly archaic: Ant 1.7 and JUnit 4 are big pluses. However its about having the right tool for the right job. I always say that if I have a gnarly old codebase then I trust Eclipse to make sense of it and get it working and get me working on it. However for Swing and Web Apps development I think nothing has really changed. You can set up a web app, framework and be experimenting in twenty minutes with NetBeans and Matisse is pretty unparalleled at the moment. With 3.3 I feel the Eclipse team have definitely done the right thing and made J2EE work a much more pleasant experience, however that was more about making up ground on NetBeans. From here on I think they need to think about how Eclipse can make other types of development easier. Personally I do think that is about bundling things like Tomcat and JavaDB into the IDE so that I can setup a configuration that includes my test databases, my test webserver and anything else I need to get my app up and running so that I am working on my code rather than my infrastructure.

Still no criticism can detract from a job well done by the Eclipse team. I just want them to do it again; and more often.

Standard