Wednesday, April 30, 2003


Sometimes Relational is Better.

I just came across another one of those problems I encounter from time to time, where trying to cram something into an object model just doesn't work.  In this case I have a many to many relationship between two classes.  Each class wants to be able to look up the other by its ID.  Hibernate does a good job of generating a relationship table that can hook these two classes together.  All is fine so far.

Now I want to characterize, optionally, each link between the two objects with a number or string.  In the relational world it's simple -- just add the field to the association table and move on to the next problem.  But we're dealing with objects, and it isn't so easy.

Sure, I can create an intervening object that contains the value I want, and I can reset the maps to point to it...but it's harder to look things up fast.  What I want is an association class here -- UML lets me do this, but...object-oriented collections libraries generally don't.

The java.util Collections library gives me key and value, but no ability to stuff something else in there, unless I use a pair-like class that sits in the middle. And since I want this relationship to be bidirectional...yuck.

See how complicated such a simple thing becomes? 

Hibernate provides "persistence for idiomatic Java", but every once in a while that's not such a good thing.  There's more to the world than objects; they do a decent job of expressing things but not a perfect one.


11:03:25 PM    

A good Java blog

. I just ran across an interesting Java related blog. A good read! [Mark Watson's Blog]

Hey, somebody thinks I have something to say.  Thanks.  Now that's one person.  Where the hell are the rest of you?  :)


10:28:52 PM    

On Hibernate.

Spent some time with Hibernate last night and I am moderately impressed. It is somewhat labor-intensive to produce a schema...you need to spend time building out an XML file that describes your object model. It doesn't read your model to figure out this information. There is some work that's been done on automatic generation of the XML mapping but it doesn't seem to be complete.

The schema generation seems to be good and efficient. You can control quite a bit of what happens with the generated schema, which is a mixed blessing. I wish I wasn't so close to the relational model when using Hibernate, but maybe that's unavoidable, if you want to achieve good performance.

Next I plan to try out TJDO and see what it does.


10:22:23 PM