AW: [Objectbridge-developers] Q: How to setup the databas e?
Brought to you by:
thma
From: Mahler T. <tho...@it...> - 2001-08-09 06:16:28
|
Hallo Christian! > -----Urspr=FCngliche Nachricht----- > Von: Christian Sell [mailto:chr...@ne...] > Gesendet: Mittwoch, 8. August 2001 18:54 > An: Mahler Thomas > Betreff: Re: [Objectbridge-developers] Q: How to setup the databas e? >=20 >=20 > Hi Thomas and all, >=20 > doe these mapping variations support polymorphism (sorry if this is > mentioned in the docs)? I.e., if I select A's via OQL, do I=20 > get B's and C's > as well - correctly instantiated, of course. >=20 Yes, Polymorphism is fully supported. That is if you select for A's = with some criteria you will get all A's, B's and C's that match this = criteria. Polymorphism works also with interfaces. That if A implements interface = IA (and B and C extending A) and you have a query on IA with some criteria = you will get all A's, B's and C's. All objects will be properly instantiated. There is a sample for this feature in test.ojb.broker with classes InterfaceArticle, Article, BookArticle and CdArticle demonstrating the respective mapping = techniques. > Option 3 seems like the most obvious mapping variation for=20 > inheritance - any > plans to support it soon? >=20 I don't agree on that. All three variants may be appropiate solutions = to model a class hierarchy. I had a lot of discussions with experienced software developers and DBA's and none of them ever used Option three. = All people I spoke to agreed that this variant is not as performant as the others as it needs a join about at least two tables for retrieving even = the simplest object of a derived class. OJB allows you to work with such a database schema if neccessary: You = have to define a 1-1 mapping between tables A and B (and A and C) and you = will need some kind of wrapper object that maintains the 1-1 relationship. That's not ideal but it works. Until now there have been no requests to implement the "Option 3", thus = I have currently no plans to implement it. (nevertheless, volunteers to do this job are always welcome :-) ) regards, Thomas > ----- Original Message ----- > From: "Mahler Thomas" <tho...@it...> > To: "'Ivan Toshkov'" <to...@cr...>; "Mahler Thomas" > <tho...@it...> > Cc: "Objectbridge (E-Mail)"=20 > <obj...@li...> > Sent: Wednesday, August 08, 2001 4:53 PM > Subject: AW: AW: AW: AW: [Objectbridge-developers] Q: How to setup = the > databas e? >=20 >=20 >=20 >=20 > > -----Urspr=FCngliche Nachricht----- > > Von: Ivan Toshkov [mailto:to...@cr...] > > Gesendet: Mittwoch, 8. August 2001 16:33 > > An: Mahler Thomas > > Betreff: Re: AW: AW: AW: [Objectbridge-developers] Q: How=20 > to setup the > > databas e? > > > > > > Hi again, > > > > I couldn't find an example of using OJB with an hierarchy=20 > of classes. > > The only exception is test.ojb.broker.Article and > > test.ojb.broker.BookArticle, but the latter does not add any > > new fields, > > so it's not exactly what I'm looking for. > > >=20 > It does! BookArticle has two additional attributes: > /** books author*/ > private String author; > /** ISBN No of Book*/ > private String isbn; >=20 > (VisualAge does not keep all attributes at the top of a class=20 > definition. I > guess that's why you did not find those attributes.) >=20 > There is also the class CdArticle that does not extend Article but > implements the interface Article and introduces also two more=20 > attributes > than Article. >=20 > > To be more specific, let's say we have the following classes: > > > > abstract class A > > { > > int num; > > } > > > > class B extends A > > { > > String name; > > } > > > > class C extends A > > { > > int count; > > } > > > > The theory says, there are generally 3 representations: > > > > 1. Store the whole hierarchy in one table: > > > > table A: > > +-----+-----+------+-------+------+ > > | oid | num | name | count | type | > > +-----+-----+------+-------+------+ > > >=20 > supported by OJB. In the ClassDescriptor of each class you=20 > just have to > declare that it maps to table A. >=20 > > 2. Store each concrete class in separate table: > > > > table B: > > +-----+-----+------+ > > | oid | num | name | > > +-----+-----+------+ > > > > table C: > > +-----+-----+-------+ > > | oid | num | count | > > +-----+-----+-------+ > > >=20 > supported by OJB. > In the ClassDescriptor for class B you have to declare that=20 > it maps to table > B (same for Class C and table C). >=20 > > 3. Store each class in a separate table: > > > > table A: > > +-----+-----+ > > | oid | num | > > +-----+-----+ > > > > table B: > > +-----+------+ > > | oid | name | > > +-----+------+ > > > > table C: > > +-----+-------+ > > | oid | count | > > +-----+-------+ > > >=20 > not directly supported. Could be relaized via a foreign key relation. >=20 > HTH, >=20 > Thomas >=20 > > Which of these are currently supported by OJB and how do the XML > > description looks like? > > > > Best regards, > > Ivan > > >=20 > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > http://lists.sourceforge.net/lists/listinfo/objectbridge-developers >=20 |