(A quick apology for any readers who have no idea what this posting is about. In my work I’ve come across a really annoying bug in some technology, and my “Googling” research didn’t come up with any good answers. It has taken me a few days to really get all of this right, so I’m hoping if some poor sod has the same problem, he or she will come across this blog posting in order to save a massive amount of time.)

I am working on an enterprise application using J2EE (JBoss) with Hibernate as the substitute for the brain-dead CMP 2.0 Entity Beans. Our development environment is Eclipse with XDoclet.

I was attempting to create an implementation of “Joined Subclasses” via the @hibernate.joined-subclass command. Here’s the really brain-dead thing: from what I can tell, this XDoclet class tag simply does not work, and I’m not sure it ever did! In my XDoclet book (and the Javadoc api page) there’s a @hibernate.joined-subclass-key which would be necessary to fully-define a joined subclass, but in the xdoclet module this tag doesn’t appear to exist. I’d found a web forum entry where someone claimed Eclipse’s autocompletion didn’t recognize it, but that you could manually type it in, but I wasn’t able to get it to work!

Essentially, it appears someone defined this in the API (because, Hell, it is really important to have to have a ‘complete’ XDoclet implementation) but I honestly see no indication that it ever worked.

Now I had to figure out how to minimize the degree by which I was screwed. The obvious solution would be to hand-craft the hibernate xml descriptors for my subclasses and manually copy them into the superclass descriptor. This would suck because then I couldn’t auto-generate the superclass descriptor without overwriting my manual entries.

But wait! If you look at the XDoclet autogenerated XML there’s a comment telling you a specific filename you could create and place in your merge directory in order to merge non-xdoclet descriptors into the superclass descriptor. To make a long story short: it didn’t seem to work. I’ve done mergepoint work before in XDoclet, but the hand-crafted definitions for the subclasses wasn’t getting inserted. There’s a chance I was doing something bone-headed, but I didn’t have time to keep hammering at that solution.

Then I looked at the Hibernate2 DTD and came to a realization: you don’t have to insert joined-subclass elements inside the superclass’s element: you can have them standalone as long as you fill in the extends=”superclass” attribute in the tag.

So here’s what I did:

1. Create the subclass, but define it as a regular @hibernate.class so that a descriptor file gets generated. (Then remove the @hibernate.class tag so XDoclet never tries to recreate a descriptor.)

2. Move the foo.hbm.xml file to a safer directory where it won’t get overwritten or erased by the build system. Hand-edit the file by removing any element that belong to the superclass, especially the id.

3. Change the tag to and inside the make sure you define a element.

Modify your packing system so these static files get included in the HAR archive or wherever you have the rest of the *.hbm.xml files. Remember, although XDoclet creates a mirror package-name directory structure for its hbm.xml files, Hibernate itself doesn’t care… it just searches for and reads every file it can find in the archive, so don’t waste time trying to get your custom hbm.xml files into the appropriate directory.

That’s it. That’s everything I know. I hope someone reads this and is saved days of fussing and can get back to productive work!