Help.
This is driving me up the wall and I would appreciate any pointers you could
give me, and I apologise if this subject has been covered before but I've
tried finding something relating to it and am getting no further forward.
I have the following d-base schema
----------- -----------
| Account |------------| Address |
----------- -----------
| |
| |
----------- |
| Contact |------------------|
-----------
Where:
Account has many Contacts
Account has many Addresses
Contact has many Addresses
My Account object has an arrayLists to store the contacts and addresses
My Contact object has an arrayList to store addresses and an account object
to point to its master object
I'm trying to get dependacies working between accounts and contacts at the
moment, if I can get that going then I can suss the rest.
What I am doing is creating an new account object, creating a new contact
object, setting the account object variable on the contact to the newly
created one and then writing the contact to the database to the dbase
This is the code I am using
NB. accountService is a wrapper around Castor.
public void testCreateAccount() throws Exception {
Mapping mapping = new Mapping();
Unmarshaller unmar;
mapping.loadMapping("C:\\jboss-tomcat-2.2\\jboss-2.2\\conf\\tomcat\\jupiter_
map.xml");
unmar = new Unmarshaller(mapping);
-- Create a new account
Account acc = new Account();
acc.setId("TESTACC1");
acc.setName("TESTACC1");
-- Create a new Contact
Contact cont = new Contact();
cont.setId("TESTCONT1");
cont.setFirstname("TESTCONT1");
-- Add account to dbase
accountService.addAccount(acc);
-- Add account to contact and write to dbase
accountService.addContact(cont,acc);
System.out.println("Added acc with linked contact");
-- Clear account and contact objects
acc = new Account();
cont = new Contact();
-- Set id on blank account object and pass to findAccount method with search
string
acc.setId("TESTACC1");
accountService.findAccount(acc,"SELECT a FROM
uk.co.servsoft.servc.dao.Account a WHERE id=$1");
System.out.println("Got account object again");
-- Get account arrayList and check for contacts
ArrayList ar = new ArrayList();
ar = acc.getContact();
Iterator i = ar.iterator();
if(i.hasNext())
{
cont = (Contact)i.next();
System.out.print("Got a contact...Name of ");
System.out.println(cont.getFirstname());
}
else
{
System.out.println("It didnae work!");
}
Here is my mapping for both account and contact, I have taken out the field
mapping for clarity
<!-- Mapping for Account -->
<class name="uk.co.servsoft.servc.dao.Account" identity="id">
<cache-type type="unlimited"/>
<map-to table="account" xml="account"/>
.......
<field name="address" type="uk.co.servsoft.servc.dao.Address"
required="true" collection="collection">
<sql many-key="addr_id"/>
<bind-xml name="address" node="element"/>
</field>
<field name="contact" type="uk.co.servsoft.servc.dao.Contact"
required="true" collection="collection">
<sql many-key="account_id"/>
<bind-xml name="contact" node="element"/>
</field>
</class>
</class>
<!-- Mapping for Contact -->
<class name="uk.co.servsoft.servc.dao.Contact" identity="id"
depends="uk.co.servsoft.servc.Account">
<cache-type type="unlimited"/>
<map-to table="contact" xml="contact"/>
.....
<field name="account" type="uk.co.servsoft.servc.dao.Account">
<sql name="account_id"/>
<bind-xml name="account" node="element"/>
</field>
<field name="address" type="uk.co.servsoft.servc.dao.Address"
required="true" collection="collection">
<sql many-key="addr_id"/>
<bind-xml name="address" node="element"/>
</field>
</class>
</mapping>
I'm not sure where I am going wrong - I have also tried getting the
arrayList from account, adding the contact to that and then re-setting the
arrayList.
ANY help would be greatly appreciated
Thanks
Mark
E-mail Disclaimer/Confidentiality Notice Private and Confidential: This
message may contain privileged/confidential information. If you are not the
intended recipient (or responsible for its delivery to such recipient),
please inform us and delete this message immediately. The notes below are an
important and integral part of this message and should be also be read
Notes: 1. It is your responsibility to carry out such virus or other checks
as are appropriate to ensure that this message and any attachments do not
affect your systems or data. This message has been virus-scanned by us
before sending but we shall not be held responsible for any effect that
there may be on your systems or data. 2. Any views, opinions, conclusions or
other information in this message which do not relate to the business of
this firm are not authorised by us. 3. Unless specifically stated in this
message and authorised by us, nothing in this message shall be taken to be
an offer or acceptance of any contract of any nature. 4. We do not accept
responsibility for any changes made to this message after it was originally
sent.
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev