Link to JIRA - https://issues.apache.org/jira/browse/TUSCANY-1895
RDB DAS - UpdateGenerator performs incorrect check when passing
property values from parent DO to child DO. It tries to find
the FK property in Parent DO and gives exception. code
.....UdateGenerator.getChangedFields() - if (!ref.isMany()) {.....
This might have remained undetected as there are no test cases with
1-1 relationship with keyRestricted=false
Could form one test case showing the failure. Please see if this is
the error you are getting and also explain for what setup you got the
exception.
CONFIG - 1-1 relationship with keyRestricted=false as below
------------
<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd">
<Command name="get named employee with company"
SQL="select * from EMPLOYEE left outer join COMPANY on EMPLOYEE.ID
= COMPANY.EOTMID where EMPLOYEE.NAME= ?" kind = "Select"/>
<Table tableName="COMPANY">
<Column columnName="ID" primaryKey="true"/>
</Table>
<Table tableName="EMPLOYEE">
<Column columnName="ID" primaryKey="true"/>
</Table>
<Relationship name="company" primaryKeyTable="EMPLOYEE"
foreignKeyTable="COMPANY" many="false" keyRestricted="false">
<KeyPair primaryKeyColumn="ID" foreignKeyColumn="EOTMID" />
</Relationship>
</Config>
--------------------------------------------------------------------------------------------------------------------------------
TEST CASE
------------------
public void testNonRestrictedOneToOneRelationshipUpdate() throws Exception {
DAS das =
DAS.FACTORY.createDAS(getConfig("OneToOneRestrictedConfig.xml"),
getConnection());
Command read = das.getCommand("get named employee with company");
read.setParameter(1, "Mary Smith");
DataObject root = read.executeQuery();
DataObject mary = root.getDataObject("EMPLOYEE[1]");
//update parent and create child
mary.setString("NAME", "maryNew");
DataObject comp = root.createDataObject("COMPANY");
comp.setInt("ID", 100);
comp.setString("NAME", "comp100");
mary.setDataObject("company", comp);
try {
das.applyChanges(root);
} catch (RuntimeException ex) {
ex.printStackTrace();
}
//refresh to see the db data
read.setParameter(1, "maryNew");
root = read.executeQuery();
mary = root.getDataObject("EMPLOYEE[1]");
comp = mary.getDataObject("company");
assertEquals(2, comp.getInt("EOTMID"));
}
--------------------------------------------------------------------------------------------------------------------------------
Result:
-----------
Invalid foreign key column: EOTMID
at
org.apache.tuscany.das.rdb.generator.impl.UpdateGenerator.getChangedFields(UpdateGenerator.java:232)
Reason:
-----------
When doing update for EMPLOYEE, UpdateGenerator tries to find property
EOTMID in DO EMPLOYEE and fails to find it.
Solution:
------------
Check similar to InsertGenerator.hasState(), this fixes the issue.
Note:
---------
Trying other combinations of relationships like 1-n, 1-1 with
keyRestricted etc. as well as autogenerated PK effect for all the
cases.
Regards,
Amita
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]