[Objectbridge-developers] RE: [objectbridge - Open Discussion] Polymorphism support?
Brought to you by:
thma
From: <tho...@it...> - 2001-01-31 16:32:16
|
Hi Sascha, > -----Urspr=FCngliche Nachricht----- > Von: nobody [mailto:no...@so...] > Gesendet: Dienstag, 30. Januar 2001 22:31 > An: no...@so... > Betreff: [objectbridge - Open Discussion] Polymorphism support? > > > Read and respond to this message at: > http://sourceforge.net/forum/message.php?msg_id=3D103071 > By: koenig > > Hi, > > I looked into ObjectBridge as a O/R mapping tool for our OpenEMed proje= ct > (http://telemed.lanl.gov/OpenEMed). > Thanks for your interest! It would be a great opportunity to proof the usability of OJB if it could solve your persistence needs. > Unfortunately I didn't found a mechanism for supporting polymorph > objects. You are right. As of today there is no support for Polymorphism. But of course it is an essential feature. It is also required by the ODMG spec. If it is a feature you need urgently I can start to work on it immediatel= y. I have already a design in mind, so it will take only a few days... > > In particular: > Our main class has a field 'value' of an interface type. This > interface type > is implemented by several concrete classes that get stored in the > 'value' field > of the main object. > I'd like to store these objects in separate tables referenced > from the main > object, but even storing them as embedded objects would be fine. > > Is there a way to do this with ObjectBridge? As long as I'm not finished with a real solution, you could try the following: you can use an additional field 'valueOID' of type String which takes a serialized representation of the concrete values Identity: valueOID =3D new Identity(value).serialize(); instead of making the field value persistent you store the serialized OID= in a db column. Of course your value field is then transient. On loading your Object you have to reconstruct it e.g. in a constructor by: value =3D (YourInterface) broker.getObjectByIdentity(Identity.forName(valueOID)); I'm using this approach for untyped Collections (like org.odmg.DList) and= it works quite well. But of course it's not type safe and brings one additio= nal level of indirection into the mapping... Of course you can also store complete serialized "embedded" objects in a single db column, but this is even worse from a design point of view... best regards, Thomas |