[ojb-users] Strange Problem with Foreign Key
Brought to you by:
thma
From: Jason M. <mc...@na...> - 2002-06-10 23:24:57
|
OK, I have a strange problem. If I instantiate an object and the run store on it, as in the following method public void editTable() { Query query = new QueryByExample(this); try { broker.beginTransaction(); Table table = (Table)broker.getObjectByQuery(query); table.setMetaID(this.getMetaID()); table.setTableName(this.getTableName()); table.setTableDesc(this.getTableDesc()); broker.store(table); broker.commitTransaction(); } catch (Exception e) { broker.abortTransaction(); log.error("Exception in editTable(): " + e); e.printStackTrace(); } } Then only the tableName and the tableDesc get updated in the database. The metaID, which is a foreign key to the database in which this table belongs does not get updated. If I change to the following, simpler method public void editTable() { try { broker.beginTransaction(); broker.store(this); broker.commitTransaction(); } catch (Exception e) { broker.abortTransaction(); log.error("Exception in editTable(): " + e); e.printStackTrace(); } } Then everything works, and the metaID gets updated. My question is...Shouldn't these two methods do exactly the same thing? Why does the first method update only two columns and not the third? Is it related to the fact that metaID is a foreign key? Or is it something to do with the objects Identity. Should I do getObjectByIdentity instead of getObjectByQuery? It's not a big issue, as it seems the second way is better anyway, but I could use some insight here. Any ideas? Thanks, Jason |