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 Thomas Mahler <th...@web.de> on 2003/05/20 08:17:20 UTC
[Fwd: OJB collection not retrieving all of the results]
-------- Original Message --------
Subject: OJB collection not retrieving all of the results
Date: Mon, 19 May 2003 20:03:07 -0500
From: McCaffrey, John G. <Jo...@kraft.com>
To: 'thma32@web.de' <th...@web.de>
Thomas,
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 ) 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 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.
Thanks,
-John
Re: Mapping two (or more) classes to one table
Posted by Alexander Prozor <ap...@isd.dp.ua>.
Hello Joerg,
in the turorial3.html file ( doc ).
see the section mapping inheritance hierarchy to the same table.
as far as I understand it's required additional column in the table
<field-descriptor
name="ojbConcreteClass"
column="CLASS_NAME"
jdbc-type="VARCHAR"
/>
or you have to derive a Class from org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl
and overwrite the method selectClassDescriptor to implement your specific type selection
mechanism
hope to help you.
JL> hi,
JL> i want to map two classes to the same table.
JL> -PartentA
JL> -ChildA
JL> -ChildB
JL> ParentA is abstract. ChildA and ChildB must be retrieved by using
JL> the same atttributes (inherited from ParentA).
JL> I tried it, but by using the unique-key as
JL> >>>crit.addEqualTo("id", "515522");
JL> the wrong class is returned.
JL> is there anything special to do in the mapping?
JL> joerg
JL> ---------------------------------------------------------------------
JL> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
JL> For additional commands, e-mail: ojb-user-help@db.apache.org
--
Best regards,
Alexander mailto:apro@isd.dp.ua
Mapping two (or more) classes to one table
Posted by Joerg Lensing <in...@softcon-lensing.de>.
hi,
i want to map two classes to the same table.
-PartentA
-ChildA
-ChildB
ParentA is abstract. ChildA and ChildB must be retrieved by using
the same atttributes (inherited from ParentA).
I tried it, but by using the unique-key as
>>>crit.addEqualTo("id", "515522");
the wrong class is returned.
is there anything special to do in the mapping?
joerg