[Objectbridge-developers] optional relationships
Brought to you by:
thma
From: Dirk O. <di...@xa...> - 2001-08-10 03:00:35
|
Hi, I just started using ObjectBridge for a small hobby project. I use it with the FrontBase dbms which had me digging around in the source a bit to make it work (wasn't hard). Now I found a problem which I could easily work around but since tihs is a common modeling case I thought of a general solution. To illustrate things better I'll just give a short description of my tables: I have a table 'Person' which has a to-many relationship to the table 'Folder'. The 'Folder' table will later have a reflexive relationship to itself (so I can have subfolders to every folder). (BTW: is that possible with ObjectBridge right now?) In order to model that, the 'Folder' table needs a foreign key which can be NULL for the case that a folder has no parent folder. This empty foreign key already throws an exception when trying to resolve the relationship from User to Folder. Since JdbcAccess tries to put values into the Folder instance using reflection it stumbles when trying to set the null foreign key. While I could work around this giving the Folder a special foreign key (e.g. 0) for the no-parent-folder case I think such cases should be handled by the framework. Currently, I could think of two possible solutions to the problem: 1) extend the mapping to let the user specify which value object he wants to have assigned for individual attributes. So there would be a <field.valueType/> in addition <field.name/> node in the mapping XML file. This would allow for e.g. Integer values to be passed. To make this work with reflection, JdbcAccess should use a set method if that's available (could be found out using reflection) 2) define an interface with methods that could let the instance itself decide what to do in such cases. E.g. we could have a method named "unableToTakeNullForField(String fieldName)". Does anyone have a better idea? -dirk |