Thank very much !

I will try it !!! 

Best regards,
Michel.

-----Mensagem original-----
De: michael simons [mailto:[EMAIL PROTECTED]
Enviada em: segunda-feira, 3 de novembro de 2003 16:41
Para: [EMAIL PROTECTED]
Assunto: Re: [castor-dev] Castor Mapping ...


Hi Michel,

The mapping goes like this:
<mapping>
...
   <class name="Order" identity="id" key-generator="HIGH-LOW">
     ...
     <field name="orderItems"  type="OrderItem" collection="collection" 
lazy="true">
       <sql many-key="orderid />
     </field>
   </class>

   <class name="OrderItem" identity="id" key-generator="HIGH-LOW">
     <field name="order" type="Order">
       <sql name="orderid" />
     </field>
   </class>

   <class name="OrderSubItem_1" extends="OrderItem" identity="id" 
key-generator="HIGH-LOW">
     ...
   </class>
   <class name="OrderSubItem_2" extends="OrderItem" identity="id" 
key-generator="HIGH-LOW">
     ...
   </class>
...
</mapping>

In the database there would be four tables
ORDER (ID, ...), ORDERITEM (ID, ...), ORDERSUBITEM_1 (ID, ...), 
ORDERSUBITEM_2(ID, ...)

note that there must be a ID field also in the ORDERSUBITEM* tables. Castor 
writes the same ID in both the ORDERITEM table and the ORDERSUBITEM* table.

So that's how to map inheritance.

The problem with Castor ist that the collection in Order would contain only 
objects of class OrderItem!

Assume you have 2 rows in ORDERSUBITEM_1, and 3 in ORDERSUBITEM_2 that both 
reference the ORDER with ID 1
I guess You would expect that the collection orderItems in the Order with 
id=1 contains 2 instances of OrderSubItem_1 and 3 instances of OrderSubItem_2,
but using Castor it contains 5 instances of OrderItem! That's why I called 
it insufficient.
Please nore that this problem is the same when using the following OQL:
"select p from OrderItem p where p.order=$1", with the Order instance of 
id=1 as parameter.

You only can work around that problem by querying the sub-items explicitly:
"select p from OrderSubItem_1 p where p.order = $1"
"select p from OrderSubItem_2 p where p.order = $1"
and putting the results in one collection on your own.

That's why I called it the bad news, because this work around will produce 
bugs in your app when anybody introduces a third sub-item.

BTW: Because of this and other insufficiencies we are evaluating Hibernate 
(www.hibernate.org) and Hibernate handles inheritance the right way. So it 
might be worth to deal with. Another reason is bug #986.

Hope this helps. Let me know if You need more information.

Regards,
Michael




At 08:23 03.11.2003 -0200, you wrote:
>Hi Michael !
>
>Yes, this is my case ! Exactly as you described. Could you give me
>some information more on how to map it or how to try it in some way ?
>
>What about the inheritance problems ?
>
>Tks and regards,
>Michel.
>
>-----Mensagem original-----
>De: michael simons [mailto:[EMAIL PROTECTED]
>Enviada em: sexta-feira, 31 de outubro de 2003 17:53
>Para: [EMAIL PROTECTED]
>Assunto: Re: [castor-dev] Castor Mapping ...
>
>
>At 08:40 31.10.2003 -0200, you wrote:
> >Hi all !
> >
> >I have a kind of ecommerce and so it has an Order object. This object
> >could have lots of itens stored in a collection property. My problem is
> >that I can have different kinds of properties for my itens and so I cannot
> >know the type of each item until I process it. In Java programming it's
> >easy, but how can I map this using Castor ? Could you help me ?
> >
> >I have already read the documentation but I did not find any example or
> >something to help me ( maybe it was not so clear to my eyes ).
> >
> >Any help would be very appreciated.
> >
> >Tks,
> >Michel Bertrand.
>
>Hi Michel,
>
>I assume your model's somehow like this
>
>class Order {
>    private java.util.Collection  orderItems;
>    ...
>}
>
>class OrderItem {
>    private Order order;
>}
>
>class OrderSubItem_1 extends OrderItem {
>...
>}
>
>class OrderSubItem_2 extends OrderItem {
>...
>}
>
>The good news is You can do this with Castor.
>The bad news is Castor's support of inheritance is insufficient.
>
>Please let me know if You need more information.
>
>Regards,
>Michael
>
>-----------------------------------------------------------
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev
>
>-----------------------------------------------------------
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to