I have just established that Castor, if used within JBoss, will not persist references to other objects.
The same code/mapping will work just fine stand-alone.
For example if we have an object of class Test reference an object of type Company, that reference will not be saved to the DB table if run in JBoss.
I suspect that I may have something misconfigured. However, dependencies (not references) are persisted correctly.
What do I need to do here? Any JBoss-Castor exeperts?
Oleg Nitz, are you there?
Thanks in advance,
-- Jacek
Environment:
JBoss 2.4.3, Oracle 8.7.1 All transactions are bean-managed, set to "RequiresNew"
This DOES NOT SAVE the reference to Company (JBOSS Session Bean)
This is a session bean (remote) method:
public Test createTest(Company c)
throws InvalidArgumentException, ReflexServerException, RemoteException
{
Company co = null;
Test t = null;
if (c == null)
throw new InvalidArgumentException("Argument cannot be null");
try {
co = (Company) pm.findByPrimaryKey(test.Company.class, new Integer(30));
t = new Test(70);
t.setOwnerCompany(co);
System.out.println("Co " + co);
System.out.println("test " + t);
pm.create(t);
}
catch (Exception ex) {
if (ex instanceof InvalidArgumentException)
throw new InvalidArgumentException(ex.getMessage());
else {
ex.printStackTrace();
throw new ReflexServerException(ex.getMessage());
}
}
return t;
}
This WORKS:
public void test() {
Company co = null;
Test t = null;
Database db;
try {
db = jdo.getDatabase();
db.setAutoStore(true);
db.begin();
writer.println("Begin transaction");
co = (Company) db.load(test.Company.class, new Integer(30));
t = new Test(70);
t.setOwnerCompany(co);
System.out.println("Co " + co);
System.out.println("test " + t);
db.create(t);
db.commit();
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("Exception " + ex);
}
}
Mapping:
<class name="test.Company" identity="companyID" key-generator="SEQUENCE">
<cache-type type="count-limited" capacity="200"/>
<description>Company</description>
<map-to table="Companies"/>
<field name="companyID" type="integer">
<sql name="companyID" type="numeric"/>
</field>
<field name="companyCode" type="string">
<sql name="code" type="varchar"/>
</field>
<field name="tests" type="test.Test" collection="arraylist">
<sql many-key="ownerCompanyID" />
</field>
</class>
<class name="test.Test" identity="testID">
<cache-type type="count-limited" capacity="200"/>
<map-to table="Tests"/>
<field name="testID" type="long">
<sql name="testID" type="numeric"/>
</field>
<field name="ownerCompany" type="test.Company">
<sql name="ownerCompanyID"/>
</field>
</class>
Numatica Corporation
E-mail: [EMAIL PROTECTED]
Phone: (781) 756 8064