-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping Existence of Component to Column?
PostPosted: Fri Nov 19, 2004 12:51 pm 
Newbie

Joined: Thu Apr 15, 2004 5:53 pm
Posts: 13
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.