Hi all, I have a problem when using m:n mapping. I will describe it below.
I just implement a tutorial in this link http://db.apache.org/ojb/docu/guides/basic-technique.html#Support+for+Non-Decomposed+m%3An+Mappings There are three table: PERSON, PROJECT, PROJECT_PERSON. PROJECT_PERSON is the connector standing for m:n relation between PROJECT and PERSON. PROJECT(id,name) PERSON(id,name) PROJECT_PERSON(project_id, person_id) The mapping file as below:____________________________ <!-- vn.com.tma.testOJB.Person --> <class-descriptor class="vn.com.tma.testOJB.Person" table="person" > <field-descriptor name="id" column="id" jdbc-type="INTEGER" primarykey="true" autoincrement="true" /> <field-descriptor name="name" column="name" jdbc-type="VARCHAR" /> <collection-descriptor name="projects" collection-class=" org.apache.ojb.broker.util.collections.ManageableArrayList" element-class-ref="vn.com.tma.testOJB.Project" auto-retrieve="true" auto-update="true" indirection-table="PROJECT_PERSON" > <fk-pointing-to-this-class column="PERSON_ID"/> <fk-pointing-to-element-class column="PROJECT_ID"/> </collection-descriptor> </class-descriptor> <!-- vn.com.tma.testOJB.Project --> <class-descriptor class="vn.com.tma.testOJB.Project" table="project" > <field-descriptor name="id" column="id" jdbc-type="INTEGER" primarykey="true" autoincrement="true" /> <field-descriptor name="name" column="Name" jdbc-type="VARCHAR" /> <collection-descriptor name="employees" collection-class=" org.apache.ojb.broker.util.collections.ManageableArrayList" element-class-ref="vn.com.tma.testOJB.Person" auto-retrieve="true" auto-update="false" indirection-table="PROJECT_PERSON" > <fk-pointing-to-this-class column="PROJECT_ID"/> <fk-pointing-to-element-class column="PERSON_ID"/> </collection-descriptor> </class-descriptor> When I run these codes, it has error: PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); Identity oid = broker.serviceIdentity().buildIdentity(Person.class, new Integer(1)); Person person = (Person) broker.getObjectByIdentity(oid); The error is caused by the third line. This is the exception stack: Exception in thread "main" org.apache.ojb.broker.PersistenceBrokerException: java.lang.NullPointerException at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.doRetrieveCollection(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollection(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.doRetrieveCollections(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollections(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getDBObject(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.doGetObjectByIdentity(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getObjectByIdentity(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByIdentity(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByIdentity(Unknown Source) at vn.com.tma.main.Run.main(Run.java:41) Caused by: java.lang.NullPointerException at org.apache.ojb.broker.accesslayer.MtoNCollectionPrefetcher.associateBatched(Unknown Source) at org.apache.ojb.broker.accesslayer.MtoNCollectionPrefetcher.prefetchRelationship(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source) ... 11 more But if I change auto-archive to "false" in arbitrary one of two class-descriptor, there is no error anymore. But it still causes the same error when I use method "broker.retrieveAllReferences()" on an instance of the rest class-descriptor. Only when I change auto-archive of both class-descriptor to "false", the error is omitted. Can anyone explain why and help me resolve the problem when using auto-archive="true" on both class-descriptor? Thank you very for your help. -- Regards, Truong Nguyen Huy