[ojb-users] Problems with M-N mappings (newbie)
Brought to you by:
thma
From: Martin F. <fu...@be...> - 2002-06-12 16:21:05
|
Hi all, I've just started using objectbridge (the 0.9 version) and am having a few problems with M-N mappings : 1) Unable to perform non-decomposed N:M mapping ====================================== I have two classes StringFDP and AndFDP. StringFDP just contains a string field, wheras AndFDP contains a Collection (of StringFDPs) (field name m_fdps) I also added a Collection field (named _containers) to StringFDP (although I don't really want this - see below) Following the test cases I did this : <class-descriptor class="prestudy.persist.bo.StringFdp" table="STRING_FDP" > <field-descriptor id="1" name="_uid" column="objid" jdbc-type="INTEGER" primarykey="true" autoincrement="true" /> <field-descriptor id="2" name="m_val" column="val" jdbc-type="VARCHAR" /> <collection-descriptor name="_containers" element-class-ref="prestudy.persist.bo.AndFdp" indirection-table="AND_FDP_ASSOC" > <fk-pointing-to-this-class column="FDP_ID"/> <fk-pointing-to-element-class column="AND_ID"/> </collection-descriptor> </class-descriptor> <class-descriptor class="prestudy.persist.bo.AndFdp" table="AND_FDP" > <field-descriptor id="1" name="_uid" column="objid" jdbc-type="INTEGER" primarykey="true" autoincrement="true" /> <collection-descriptor name="m_fdps" element-class-ref="prestudy.persist.bo.StringFdp" indirection-table="AND_FDP_ASSOC" > <fk-pointing-to-this-class column="AND_ID"/> <fk-pointing-to-element-class column="FDP_ID"/> </collection-descriptor> </class-descriptor> This gave me a NPE during a lock operation (I had to modify TransactionImpl to print the cause of the exception rather than just the LockNotGrantedException) : java.lang.NullPointerException at ojb.broker.metadata.ObjectReferenceDescriptor.getForeignKeyFieldDescr iptors(ObjectReferenceDescriptor.java:250) at ojb.odmg.TransactionImpl.lockCollections(Unknown Source) at ojb.odmg.TransactionImpl.register(Unknown Source) at ojb.odmg.TransactionImpl.lock(Unknown Source) at prestudy.persist.ojb.OjbFdpStorer.save(OjbFdpStorer.java:72) at prestudy.persist.ojb.OjbFdpStorer.test(OjbFdpStorer.java:119) at prestudy.persist.ojb.OjbFdpStorer.main(OjbFdpStorer.java:94) org.odmg.LockNotGrantedException at ojb.odmg.TransactionImpl.lock(Unknown Source) at prestudy.persist.ojb.OjbFdpStorer.save(OjbFdpStorer.java:72) at prestudy.persist.ojb.OjbFdpStorer.test(OjbFdpStorer.java:119) at prestudy.persist.ojb.OjbFdpStorer.main(OjbFdpStorer.java:94) It seems OJB wants a foreign key definition. But the unit test case the non-decomposed mapping PEOPLE, PROJECTS using indirection_table works fine. The only difference I can see is that in the unit test there is _also_ a decomposed mapping between the same two classes (via ROLE). In tutorial 3 a seemingly dummy reverse_fk_descriptor is used (999) but when I add this I get an ArrayIndexOutOfBoundsException. 2) How do I do a unidirectional N:M mapping? ================================= In fact my object model only needs navigability from AndFdp to StringFdp and not the inverse. Why do I have to add an unneeded Collection to my StringFdp class. 3) What I'm really trying to do. ====================== In fact I'm really trying to map a composite pattern structure of objects where each object is either a simple object (such as StringFdp) or a composite (such as AndFdp). The idea being to have several composites representing logical operations (Or, Nand etc). Is it possible to map this type of model? Help much appreciated, Martin Fuzzey |