I have an object Agency which contains an Address, which has id as an
attribute. In the tables (MySQL), Agency refers to the primary key of
the Address table, address_id.
The relevant mapping.xml portion looks like this:
<!-- Mapping for Agency -->
<class name="spi.copyhelpers.AgencyCopyHelper"
identity="id" key-generator="IDENTITY">
<description>Agency</description>
<map-to table="Agency" />
<field name="id" type="integer" >
<sql name="agency_id" type="integer"/>
</field>
<field name="name" type="string">
<sql name="name" type="char" dirty="check" />
</field>
<field name="address" type="spi.copyhelpers.AddressCopyHelper">
<sql name="address_id" />
</field>
<field name="phoneNumber" type="string">
<sql name="phone_num" type="char" dirty="check" />
</field>
<field name="faxNumber" type="string">
<sql name="fax_num" type="char" dirty="check" />
</field>
<field name="website" type="string">
<sql name="website" type="char" dirty="check" />
</field>
</class>
<!-- Mapping for Address -->
<class name="spi.copyhelpers.AddressCopyHelper"
identity="id" key-generator="IDENTITY">
<description>Address</description>
<map-to table="Address" />
<field name="id" type="integer" >
<sql name="address_id" type="integer"/>
</field>
<field name="streetAddress1">
<sql name="address_line_1"/>
</field>
<field name="streetAddress2">
<sql name="address_line_2"/>
</field>
<field name="city">
<sql name="city"/>
</field>
<field name="state" type="spi.domainobjects.State">
<sql name="state"/>
</field>
<field name="postalCode">
<sql name="postal_code"/>
</field>
<field name="country" type="spi.domainobjects.Country">
<sql name="country"/>
</field>
</class>
First, I add a new Agency and Address, and the address_id in the Agency
table correctly refers to the new Address created. Then, I immediately
query all of the Agencies in the system inside a new transaction. I
then iterate through the Agencies, adding them to a Vector to display
later. If I look at the Agency table before I commit, it still points
to the correct address_id. However, once I call commit, Castor thinks
that the last Agency read in is dirty, so it stores it. This would not
be a problem except for that the address_id in the Agency table for that
Agency is now 0 even though it was correct inside the object only
moments ago. Any idea on what's going on?
Here is the query code:
db.begin();
OQLQuery oql = db.getOQLQuery("SELECT o FROM
spi.copyhelpers.AgencyCopyHelper o");
QueryResults results = oql.execute();
while (results.hasMore()) {
items.add(results.next());
}
db.commit();
Thanks.
--
Chris Bonham
President/CEO
Third Eye Consulting, Inc.
[EMAIL PROTECTED]
http://www.thirdeyeconsulting.com
317.823.3686
317.823.0353 (FAX)
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev