I've got a fairly fundamental object mapping question, that I'm hoping to get help with.
The portion of my object model I'm concerned with here has to do with an Entity called Bond. A Bond has some coupons, which can be one of two types: FixedMaturing or FloatingMaturing.
In conceptual terms, the coupons object is a component of Bond. Ideally, I'd like to have that concept carried over in to the Hibernate mapping... for example, I wouldn't want to call save() on the Coupons object, I should just call save on the containing Bond. And a Coupons object shouldn't need an ID or a version, cause it's really just a field of the Bond.
My understanding though is that if you want to use polymorphic objects, you must use Entities. So we've got a Coupons base class, which in turn has two subclasses.
This works ok, but there's one thing about it that bugs me, which is that if I modify the Coupons object by changing one of it's fields, Hibernate doesn't see that the Bond object is dirty and should have it's version updated, although the Coupons object does.
Is there a better way to model polymorphic 'component' type objects?
I've come up with a couple of ideas, but I'm not sure how well they'd work:
Make a component object that can store all the varied fields of the Coupons subclasses, and take care of instantiating the correct subtype of Coupons myself. That seems a bit awkward though, as I'd basically be reimplementing what Hibernate does with it's entity subclass handling.
Implement an Interceptor that, onFlushDirty of a Coupons object, does something to the containing Bond to mark it as dirty.
Any advice?
Hibernate version:
2.1.7c, but upgrading to up-to-date version shortly.
|