Is there any way to map the existence of a component to a database column?
For instance -- imagine a 'Car' class with an attached 'Spoiler' object. The spoiler object is a small value object with very little information (height, shape). Accordingly, when doing the mapping, we've decided to collapse the spoiler object to the two fields within the CAR table (CAR.SPOILER_HEIGHT, CAR.SPOILER_SHAPE).
In the object model, we have a natural way to indicate whether or not a car has a spoiler - by attaching a Spoiler object, or not. We can even add a convenience method Car.hasSpoiler():boolean.
Unfortunately, when we map this to the database, we lose this natural mapping -- the table simply has two fields which may or may not be null. We can interrogate the fields to see if they are null, but that lacks the explicitness of a field that indicates that the car has a spoiler (e.g. CAR.HAS_SPOILER).
We can also add a 'hasSpoiler' (or 'exists') private field to the spoiler, and map that to CAR.HAS_SPOILER, but that field has no meaning in the object world, so I'd prefer not to have to put it there.
What I'd really prefer is it Hibernate could mark the existence or non-existence of the component object into a field somehow, and determine, (through hasSpoiler() or whether or not Car.getSpoiler() is null) the value of the CAR.HAS_SPOILER field.
Context Information:
Hibernate 2.1.3 (although if there's a solution in another version, I'm not hung up on the version).
All the above example is a simplified hypothetical, so I don't have code or mapping files to share.
_________________ --
Geoffrey Wiseman
|