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 "Gibbs, Tim" <Ti...@rbccm.com> on 2003/07/30 03:54:18 UTC

Problems with collection-descriptor

I have a table that looks like this

my_business_object
{
	business_object_id int;  // this is the primary key
	other_object_id int;
}

And I have a relationship table that relates business objects that looks
like

relationship
{
	party1_id int;  // part of primary key
	party2_id int; // part of primary key
	relationship_type_id; // part of primary key
}

Unfortunately I inherited this schema so what I need to do is a little out
of the ordinary.

I need to find all the rows from my_business_objects where the
other_object_id is the field that I want to map to party1 and party2

For example the sql that I would like is:

select * from my_business_object where other_object_id = party1 and
party2_id = 1 and relationship_type_id = 2

The problem with this is that OJB doesn't like the fact that I am trying to
build a collection descriptor based on a key in my_business_object table
that is not the primary key.  

For example if I define the descriptor as follows:

<class-descriptor class="com.something.MyBusinessObject"
table="my_business_object">
<field-descriptor name="otherObjectId" column="other_object_id"
jdbc-type="INTEGER"/>
<field-descriptor name="businessObjectId" column="business_object_id"
jdbc-type="INTEGER" autoincrement="true"
sequence-name="get_business_object_id" primarykey="true"/>
<collection-descriptor name="relationshipsAsParty1"
element-class-ref="com.something.Relationship" auto-retrieve="false"
auto-update="false" auto-delete="false">
			<inverse-foreignkey field-ref="party1Id"/> 
	
</collection-descriptor>
</class-descriptor>

When I try to query something where the criteria is something like
"relationshipAsParty1.party2Id = 1 and
relationshipsAsParty1.relationshipTypeId = 2" it tries to do the join back
to the my_business_object table throught the primary key attribute
businessObjectId.  e.g. I get the following sql:

select * from my_business_object where business_object_id = party1 and
party2_id = 1 and relationship_type_id = 2

INSTEAD of what I want which is :

select * from my_business_object where other_object_id = party1 and
party2_id = 1 and relationship_type_id = 2

Is there any way that I can tell OJB to join with something other than the
primary key in this instance.

Thanks for any info.

Tim





<font face="Times New Roman" size="3">
<p>------------------------------------------------------------------------------</p>
<p> This e-mail may be privileged and/or confidential, and the sender does not waive any related rights and obligations. Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized. If you received this e-mail in error, please advise me (by return e-mail or otherwise) immediately.</p>
<p> Ce courriel est confidentiel et protégé. L'expéditeur ne renonce pas aux droits et obligations qui s'y rapportent. Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il contient par une personne autre que le (les) destinataire(s) désigné(s) est interdite. Si vous recevez ce courriel par erreur, veuillez m'en aviser immédiatement, par retour de courriel ou par un autre moyen.</p>
<p>====================================================</p>
</font>