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