Hi Low, Thank you. I modified the mapping. It works. Buchi -----Original Message----- From: Low Heng Sin [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 28, 2001 6:17 PM To: [EMAIL PROTECTED] Subject: Re: [castor-dev] Problem with loading objects involved in 1:M Map ping Hi, Your mapping is not correct : <?xml version = "1.0"?> <mapping> <class name="test.Station" identity="id"> <map-to table="STATION" xml="Station"/> <field name="id" type="long" required="true"> <sql name="id" type="bigint"/> </field> <field name="name" type="string"> <sql name="name" type="char"/> </field> <field name="invoices" type="test.Invoice" collection="vector"> <sql many-key="station_id"/> </field> </class> <class name="test.Invoice" identity="id"> <map-to table="INVOICE" xml="Invoice"/> <field name="id" type="long" required="true"> <sql name="id" type="bigint"/> </field> <field name="invoiceDate" type="java.util.Date"> <sql name="invoice_date" type="date"/> </field> <field name="num" type="string"> <sql name="num" type="char"/> </field> <field name="Station" type="test.Station" required="true"> <sql name="station_id"/> </field> <field name="lineItems" type="test.InvoiceItem" collection="vector"> <sql many-key="invoice_id"/> </field> </class> <class name="test.InvoiceItem" identity="id" depends="test.Invoice"> <map-to table="INVOICE_ITEM" xml="InvoiceItem"/> <field name="id" type="long"> <sql name="id" type="bigint"/> </field> <field name="invoice" type="test.Invoice" required="true"> <sql name="invoice_id"/> </field> <field name="name" type="string"> <sql name="name" type="char"/> </field> <field name="amount" type="double" required="true"> <sql name="amount" type="numeric"/> </field> </class> </mapping> -----Original Message----- From: Pasupuleti, Bharath [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 29, 2001 4:48 To: [EMAIL PROTECTED] Subject: [castor-dev] Problem with loading objects involved in 1:M Mapping Hi, I am having a problem loading objects involved in 1:M mapping. Each invoice has a collection(vector) of invoice items. It is a whole-part component relationship and the reference is bidirectional. The mapping file is defined as follows --- <?xml version = "1.0"?> <mapping> <class name="test.Station" identity="id"> <map-to table="STATION" xml="Station"/> <field name="id" type="long" required="true"> <sql name="id" type="bigint"/> </field> <field name="name" type="string"> <sql name="name" type="char"/> </field> <field name="invoices" type="test.Invoice" collection="vector"> <sql many-key="id"/> </field> </class> <class name="test.Invoice" identity="id"> <map-to table="INVOICE" xml="Invoice"/> <field name="id" type="long" required="true"> <sql name="id" type="bigint"/> </field> <field name="invoiceDate" type="java.util.Date"> <sql name="invoice_date" type="date"/> </field> <field name="num" type="string"> <sql name="num" type="char"/> </field> <field name="Station" type="test.Station" required="true"> <sql name="station_id"/> </field> <field name="lineItems" type="test.InvoiceItem" collection="vector"> <sql many-key="invoice_id"/> </field> </class> <class name="test.InvoiceItem" identity="id" depends="test.Invoice"> <map-to table="INVOICE_ITEM" xml="InvoiceItem"/> <field name="id" type="long"> <sql name="id" type="bigint"/> </field> <field name="invoice" type="test.Invoice" required="true"> <sql many-key="id"/> </field> <field name="name" type="string"> <sql name="name" type="char"/> </field> <field name="amount" type="double" required="true"> <sql name="amount" type="numeric"/> </field> </class> </mapping> Here is the code snippet - OQLQuery invoiceOQL; QueryResults results; // Start the transaction db.begin(); //Get an invoice; invoiceOQL = db.getOQLQuery("SELECT inv FROM test.Invoice inv WHERE id=1"); results = invoiceOQL.execute(); while(results.hasMore()) { Invoice inv = (Invoice) results.next(); System.out.println("INVOICE ID : " + inv.getId()); System.out.println("STATION ID : " + inv.getStation().getId()); Vector v = (Vector) inv.getLineItems(); System.out.println("INVOICEITEMS VECTOR SIZE : " + v.size()); Iterator itr = v.iterator(); while(itr.hasNext()) { InvoiceItem i = (InvoiceItem) itr.next(); System.out.println("Name : " + i.getName()); System.out.println("Amount : " + i.getAmount()); } } // Commit the transaction db.commit(); When I try to query for an invoice, it loads all fields of invoice except invoice items(Vector). The invoice items vector size is zero. I guess Castor is not comparing the PK of invoice with the FK of invoice item in the sql SELECT statement. Any help would be greatly appreciated, Regards, Buchi. ----------------------------------------------------------- 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
