I get "Could not obtain next object: null" exception when i try to read
records for a 1-N relation.
va.util.NoSuchElementException: Could not obtain next object: null
at
org.apache.ojb.broker.accesslayer.RsIterator.next(RsIterator.java:270)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(PersistenceBrokerImpl.java:1340)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(PersistenceBrokerImpl.java:1463)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(PersistenceBrokerImpl.java:1499)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(PersistenceBrokerImpl.java:1488)
at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(DelegatingPersistenceBroker.java:302)
at
com.lilly.xrep.basebusiness.ExperimentManager.printProject(ExperimentManager.java:109)
at
com.lilly.xrep.basebusiness.ExperimentManager.main(ExperimentManager.java:46)
Description:
In our application a Project has Multiple Experiments defined as follows
<class-descriptor class="com.lilly.xrep.basebusiness.Project"
table="XRP_OWNER.XRP_PROJECT" >
<field-descriptor id="1" name="_projectId"
column="PROJECT_ID" jdbc-type="BIGINT" primarykey="true"/>
<field-descriptor id="2" name="_projectDescription"
column="PROJECT_DESCRIPTION" jdbc-type="VARCHAR"/>
<field-descriptor id="3" name="_projectKeywords"
column="PROJECT_KEYWORDS" jdbc-type="VARCHAR"/>
<field-descriptor id="4" name="_therapeuticArea"
column="THERAPEUTIC_AREA" jdbc-type="VARCHAR"/>
<field-descriptor id="5" name="_diseaseStateTarget"
column="DISEASE_STATE_TARGET" jdbc-type="VARCHAR"/>
<collection-descriptor name="_experimentList"
element-class-ref="com.lilly.xrep.basebusiness.Experiment"
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
auto-retrieve="true" auto-update="false" auto-delete="false"
orderby="_projectId" sort="DESC">
<inverse-foreignkey field-id-ref="6"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor class="com.lilly.xrep.basebusiness.Experiment"
table="XRP_OWNER.XRP_EXPERIMENT">
<field-descriptor id="1" name="_experimentId"
column="EXPERIMENT_ID" jdbc-type="BIGINT" primarykey="true"/>
<field-descriptor id="2" name="_notebookNo"
column="NOTEBOOK_NO" jdbc-type="VARCHAR"/>
<field-descriptor id="3" name="_experimentDate"
column="EXPERIMENT_DATE" jdbc-type="TIMESTAMP"/>
<field-descriptor id="4" name="_investigatorId"
column="INVESTIGATOR_ID" jdbc-type="BIGINT"/>
<field-descriptor id="5" name="_studyNo" column="STUDY_NO"
jdbc-type="VARCHAR"/>
<field-descriptor id="6" name="_projectId"
column="PROJECT_ID" jdbc-type="BIGINT"/>
<field-descriptor id="7" name="_purpose" column="PURPOSE"
jdbc-type="VARCHAR"/>
<field-descriptor id="8" name="_design" column="DESIGN"
jdbc-type="VARCHAR"/>
<reference-descriptor name="_project"
class-ref="com.lilly.xrep.basebusiness.Project" auto-retrieve="true"
auto-update="false" auto-delete="false">
<foreignkey field-id-ref="6"/>
</reference-descriptor>
Project Class definition goes like this
public class Project extends
com.lilly.xrep.basebusiness.BaseBusinessObject
implements java.io.Serializable,ProjectInterface
{
//--------------------------/
//- Class/Member Variables -/
//--------------------------/
private java.lang.Long _projectId;
private java.lang.String _projectDescription;
private java.lang.String _projectKeywords;
private java.lang.String _therapeuticArea;
private java.lang.String _diseaseStateTarget;
private java.util.ArrayList _experimentList;
//get/set methods....
}
Experiment Class definition goes like this
public class Experiment extends
com.lilly.xrep.basebusiness.BaseBusinessObject
implements java.io.Serializable,ExperimentInterface
{
protected ProjectInterface _project;
private java.lang.Long _experimentId;
private java.lang.String _notebookNo;
private java.util.Date _experimentDate;
private java.lang.Long _investigatorId;
private java.lang.String _studyNo;
private java.lang.Long _projectId;
private java.lang.String _purpose;
private java.lang.String _design;
private Investigator _investigator;
// get/set methods
}
Iam trying to extract a group of Projects and their associated Experiments
by the following code
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
Criteria crit = new Criteria();
Long t = new Long(10002);
crit.addLessOrEqualThan("_projectId", t);
QueryByCriteria q = new QueryByCriteria(Project.class, crit);
q.addPrefetchedRelationship("_experimentList");
Collection results = broker.getCollectionByQuery(q);
I get the above exception on executing this (using Oracle database).
Please help.
Many thanks for your support.
Regards,
Zabi.