Attached are my codes. I hope that they can help. Mine works probably. If
you don't mind, you may send me some code segments so that I can see if
there is any difference. Or, if you can find difference, please tell me so
that I can learn from it. Thank you.
-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 18 October 2001 12:57 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] advise
Hi Hudson
Thanks again. I have another question, this time it's a 1:1 relationship.
Looking at your mapping file, the PurchaseOrder has this field:
<field name="customer" type="com.au.tpg.research.Customer"
required="true">
<sql name="customer_id" />
<xml name="customer" node="element" />
</field>
If you:
(1) lookup a Customer object
(2) assign it to the PurchaseOrder object
(3) create the PurchaseOrder
does Castor fill in the customer_id in your DB? Mine appears to be null.
Regards
Keith C
-----Original Message-----
From: Hudson Wong [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 17 October 2001 5:16 p.m.
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] advise
Yes, it works. I have tried it before I send it.
Following is my mapping and my code. I hope I have not misinterpreted your
question.
private void lineItemQueryTest() throws Exception {
cat.info("lineItemQueryTest");
String queryString = "select po.id " +
"from com.au.tpg.research.PurchaseOrder po " +
"where po.lineItemSet.id = $1";
OQLQuery query = db.getOQLQuery(queryString);
query.bind(111);
QueryResults results = query.execute();
while (results.hasMore()) {
Object obj = results.next();
cat.info(obj.getClass().getName() + ":-" + obj);
}
}
<class name="com.au.tpg.research.Customer"
identity="id" key-generator="HIGH/LOW">
<description>Customer</description>
<map-to table="customer" xml="customer" />
<field name="id" type="integer" >
<sql name="customer_id" type="integer"/>
<xml node="attribute"/>
</field>
<field name="name" type="string">
<sql name="customer_name" type="varchar" dirty="check" />
<xml node="text" />
</field>
<field name="order" type="com.au.tpg.research.PurchaseOrder"
collection="set" get-method="friendGetOrderSet"
set-method="friendSetOrderSet">
<sql many-key="customer_id"/>
</field>
</class>
<class name="com.au.tpg.research.Product"
identity="id" key-generator="HIGH/LOW">
<description>Product definition</description>
<map-to table="product" xml="product" />
<field name="id" type="integer" required="true">
<sql name="product_id" type="integer" />
<xml node="attribute"/>
</field>
<field name="name" type="string" required="true">
<sql name="product_name" type="varchar" />
<xml node="element" />
</field>
</class>
<class name="com.au.tpg.research.PurchaseOrder"
identity="id" key-generator="HIGH/LOW">
<description>Product definition</description>
<map-to table="purchase_order" xml="order" />
<field name="id" type="integer" required="true">
<sql name="order_id" type="integer" />
<xml node="attribute"/>
</field>
<field name="orderNo" type="string" required="true">
<sql name="order_no" type="varchar"/>
</field>
<field name="orderDate" type="date" required="true">
<sql name="order_date" type="timestamp" />
<xml node="element" />
</field>
<field name="customer" type="com.au.tpg.research.Customer"
required="true">
<sql name="customer_id" />
<xml name="customer" node="element" />
</field>
<field name="lineItemSet" type="com.au.tpg.research.LineItem"
required="true"
collection="set" get-method="friendGetLineItemSet"
set-method="friendSetLineItemSet">
<sql many-key="order_id"/>
<xml name="lineItem" node="element" />
</field>
</class>
<class name="com.au.tpg.research.LineItem" identity="id"
depends="com.au.tpg.research.PurchaseOrder" key-generator="HIGH/LOW">
<description>Product detail</description>
<map-to table="purchase_order_line_item" xml="lineItem" />
<field name="id" type="integer" required="true">
<sql name="line_item_id" type="integer"/>
<xml node="attribute"/>
</field>
<field name="order" type="com.au.tpg.research.PurchaseOrder"
required="true">
<sql name="order_id"/>
<xml node="attribute"/>
</field>
<field name="product" type="com.au.tpg.research.Product"
required="true">
<sql name="product_id" />
<xml name="product" node="element" />
</field>
<field name="quantity" type="integer" required="true">
<sql name="quantity" type="integer"/>
<xml node="element" />
</field>
</class>
-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 17 October 2001 1:40 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] advise
Hi Hudson
Unfortunately, this is a 1:n relationship. There is a vector of Password
objects in the User object.
I have not tried it, but I doubt u.passwords.id = $1 will work, since
passwords is a vector. Hmmm, will it work? I'll give it a go.
Keith C
-----Original Message-----
From: Hudson Wong [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 17 October 2001 4:33 p.m.
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] advise
Do you think that the following query may solve the problem?
select u
from User u
where u.password.id = $1
while $1 is the password identifier and so on
-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 17 October 2001 1:02 PM
To: [EMAIL PROTECTED]
Subject: [castor-dev] advise
Hi
I need some guidance/advise. I have a User object with many Password objects
(1:n relationship). I have setup the mapping to make Password depend on User
(using "depends" attribute).
Castor handles the loading and deletion perfectly. However, I can only
perform create/load/delete via the master object (ie User), and not on the
child (ie Password). This is because Castor wants to maintain referential
integrity.
Now, my question is: Given a password, how do I determine which user it
belongs to?
APPROACH 1
==========
One way is to load all user objects and loop through them to check if the
password matches. This is slow, but seem to be the only way in Castor.
APPROACH 2
==========
The alternative is to remove the Password <-> User dependency. Then we can
search on the passwords, and finally retrieve the users (password table will
have user_id field).
Approach 2 is fast, but the drawback is that the application now has to
maintain referential integrity.
I love Castor maintaining the object relationship. But it does not allow me
to search the Password objects.
How will you approach this problem? Please advise.
Keith C
-----------------------------------------------------------
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
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
Customer.java
PurchaseOrder.java
LineItem.java
Product.java
OneToManyTest.java