Re: [Objectbridge-developers] optional relationships
Brought to you by:
thma
From: David F. <dw...@la...> - 2001-08-10 03:39:59
|
At 08:51 PM 8/9/2001, Dirk Olmes wrote: >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?) Yes, it does. We are using it this way now. One of my applications has the same structure. It has an "Identity: object which contains many "Traits" Traits can contain other Traits. I have two tables Identity and Trait >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. In my case I don't allow for a Trait to exist by itself, so a Trait has a Trait or an Identity as a parent. I don't formally use a foreign key. >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: We have another application that handles the case as you indicate for the "top of the tree" Our objects can be handled by OJB or other Object-Relational mapping tools as well as directly by an OODBMS. I don't like to have a method like "2)" unless it has some other benefit to the object. I hope this helps a little, Dave >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 > >_______________________________________________ >Objectbridge-developers mailing list >Obj...@li... >http://lists.sourceforge.net/lists/listinfo/objectbridge-developers David W. Forslund dw...@la... Computer and Computational Sciences http://www.acl.lanl.gov/~dwf Los Alamos National Laboratory Los Alamos, NM 87545 505-663-5218 FAX: 505-665-4939 |