You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by "McCaffrey, John G." <Jo...@kraft.com> on 2003/05/20 16:45:01 UTC

OJB collection not retrieving all of the results

HI I am new to OJB, but have been looking forward to using it for some time.
I am currently having a problem retrieving objects that contain a collection
of child objects.( A BrokerVO Has a collection of BpCntctVOs ) I have looked
through the mailing list, but I haven't found this problem yet. Here is my
repository XML:

<class-descriptor class="com.kraft.esi.msf.broker.BrokerVO"
table="m01.brkr">
	<field-descriptor id="1" name="brkrNbr" column="BP_NBR"
jdbc-type="BIGINT" primarykey="true"/>
	<field-descriptor id="2" name="vendNbr" column="AP_VNDR_NBR"
jdbc-type="VARCHAR" />
	<field-descriptor id="3" name="brkrEffStrtDate"
column="EFCT_STRT_DT" jdbc-type="DATE"
	
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDateFi
eldConversion"/>
	<field-descriptor id="4" name="brkrEffEndDate" column="EFCT_END_DT"
jdbc-type="DATE" 
	
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDateFi
eldConversion"/>
	<field-descriptor id="5" name="brkrComment" column="CMNT"
jdbc-type="VARCHAR"/>
		
	<collection-descriptor  name="businessContacts"
element-class-ref="com.kraft.esi.msf.broker.BpCntctVO" 
	 	auto-retrieve="true" auto-update="false" auto-delete="false"
orderby="cntctTypeCode" sort="ASC" >
       	<inverse-foreignkey  field-id-ref="1"/>
      </collection-descriptor>  
</class-descriptor> 
	
	
<class-descriptor class="com.kraft.esi.msf.broker.BpCntctVO"
table="m01.bp_cntct">
	<field-descriptor id="1" name="bpNbr" column="BP_NBR"
jdbc-type="DECIMAL" primarykey="true"/>
	<field-descriptor id="2" name="lastName" column="LAST_NM"
jdbc-type="VARCHAR" />
	<field-descriptor id="3" name="firstName" column="FIRST_NM"
jdbc-type="VARCHAR"/>
	<field-descriptor id="4" name="phoneNbr" column="PHONE_NBR"
jdbc-type="DECIMAL"/>
	<field-descriptor id="5" name="emailAddr" column="EMAIL_ADR"
jdbc-type="VARCHAR"/>
	<!-- one day it may be possible to have more than one manager of
each type, when that happens, we will have
	to add the CNTCT_NBR field as a primary key -->
	<field-descriptor id="6" name="cntctTypeCode" column="CNTCT_TYP_CD"
jdbc-type="CHAR" primarykey="true"/>
</class-descriptor> 

my problem is that when I do a search that I know should return multiple
rows (select * from brkr where varchar(bp_Nbr) like '8227%' it is only
returning one row. If I run the code again, a second row is found (and each
time I run the code it will continue to add rows to the collection, as if
its a proxy). If I comment out the collection descriptor (or set
auto-retrieve="false") in the repository.xml and run the query, it finds all
of the rows right away. The collection that I am using in the class is just
Collection, not a typed collection.
The query that I am running is 

//.. equalCrit has values set to it
if (brokerVO.getBrkrNbr() != null && 	brokerVO.getBrkrNbrModified() ==
true)
{
  Criteria like = new Criteria();
  like.addLike(" varchar (BP_NBR)", brokerVO.getBrkrNbr() + "%");
  equalCrit.addAndCriteria(like);
}

Query query = new QueryByCriteria(brokerVO.getClass(), equalCrit, false);
returnVOCol = (Collection)persistanceBroker.getCollectionByQuery(query);

//..

I am not sure what I am diong wrong, if its the foreign key, or that I need
to create a typed collection, or I need to do the Query differently. I wish
that I could see the SQL that OJB uses to get the child object, I think that
would help me. I am using a datasource & websphere, but I think I can get
P6spy to work with that.

Thanks,
-John



Re: OJB collection not retrieving all of the results

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi john,

why don't you simply  equalCrit.addLike ?
some sql-traces would also be helpful.

jakob

McCaffrey, John G. wrote:

>HI I am new to OJB, but have been looking forward to using it for some time.
>I am currently having a problem retrieving objects that contain a collection
>of child objects.( A BrokerVO Has a collection of BpCntctVOs ) I have looked
>through the mailing list, but I haven't found this problem yet. Here is my
>repository XML:
>
><class-descriptor class="com.kraft.esi.msf.broker.BrokerVO"
>table="m01.brkr">
>	<field-descriptor id="1" name="brkrNbr" column="BP_NBR"
>jdbc-type="BIGINT" primarykey="true"/>
>	<field-descriptor id="2" name="vendNbr" column="AP_VNDR_NBR"
>jdbc-type="VARCHAR" />
>	<field-descriptor id="3" name="brkrEffStrtDate"
>column="EFCT_STRT_DT" jdbc-type="DATE"
>	
>conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDateFi
>eldConversion"/>
>	<field-descriptor id="4" name="brkrEffEndDate" column="EFCT_END_DT"
>jdbc-type="DATE" 
>	
>conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDateFi
>eldConversion"/>
>	<field-descriptor id="5" name="brkrComment" column="CMNT"
>jdbc-type="VARCHAR"/>
>		
>	<collection-descriptor  name="businessContacts"
>element-class-ref="com.kraft.esi.msf.broker.BpCntctVO" 
>	 	auto-retrieve="true" auto-update="false" auto-delete="false"
>orderby="cntctTypeCode" sort="ASC" >
>       	<inverse-foreignkey  field-id-ref="1"/>
>      </collection-descriptor>  
></class-descriptor> 
>	
>	
><class-descriptor class="com.kraft.esi.msf.broker.BpCntctVO"
>table="m01.bp_cntct">
>	<field-descriptor id="1" name="bpNbr" column="BP_NBR"
>jdbc-type="DECIMAL" primarykey="true"/>
>	<field-descriptor id="2" name="lastName" column="LAST_NM"
>jdbc-type="VARCHAR" />
>	<field-descriptor id="3" name="firstName" column="FIRST_NM"
>jdbc-type="VARCHAR"/>
>	<field-descriptor id="4" name="phoneNbr" column="PHONE_NBR"
>jdbc-type="DECIMAL"/>
>	<field-descriptor id="5" name="emailAddr" column="EMAIL_ADR"
>jdbc-type="VARCHAR"/>
>	<!-- one day it may be possible to have more than one manager of
>each type, when that happens, we will have
>	to add the CNTCT_NBR field as a primary key -->
>	<field-descriptor id="6" name="cntctTypeCode" column="CNTCT_TYP_CD"
>jdbc-type="CHAR" primarykey="true"/>
></class-descriptor> 
>
>my problem is that when I do a search that I know should return multiple
>rows (select * from brkr where varchar(bp_Nbr) like '8227%' it is only
>returning one row. If I run the code again, a second row is found (and each
>time I run the code it will continue to add rows to the collection, as if
>its a proxy). If I comment out the collection descriptor (or set
>auto-retrieve="false") in the repository.xml and run the query, it finds all
>of the rows right away. The collection that I am using in the class is just
>Collection, not a typed collection.
>The query that I am running is 
>
>//.. equalCrit has values set to it
>if (brokerVO.getBrkrNbr() != null && 	brokerVO.getBrkrNbrModified() ==
>true)
>{
>  Criteria like = new Criteria();
>  like.addLike(" varchar (BP_NBR)", brokerVO.getBrkrNbr() + "%");
>  equalCrit.addAndCriteria(like);
>}
>
>Query query = new QueryByCriteria(brokerVO.getClass(), equalCrit, false);
>returnVOCol = (Collection)persistanceBroker.getCollectionByQuery(query);
>
>//..
>
>I am not sure what I am diong wrong, if its the foreign key, or that I need
>to create a typed collection, or I need to do the Query differently. I wish
>that I could see the SQL that OJB uses to get the child object, I think that
>would help me. I am using a datasource & websphere, but I think I can get
>P6spy to work with that.
>
>Thanks,
>-John
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>  
>