Armin,
Hi Chris,
Chris Worley wrote:
In the following code I get a ClassCastException when querying for
the PartyGroup or Person. PartyGroup and Person both extend Party.
Party.partyTypeId will determine if the party is a person or party
group. If the party is one of the two then I want to get the party
group or person object and return it. However, when the code queries
a second time for the person or party group a ClassCastException
occurs. getObjectByIdeneity(...) is retruning an instance of CParty,
even though when the Identity was build I passed CPartyGroup.class as
the param no CParty.class.
If I modify the code not to query for CParty first and just query for
CPartyGroup I will get an instance of CPartyGroup. But, for some
reason by building the CParty identity first the second attempt for
CPartyGroup still returns an instance of CParty. ....and I have no
idea why.
Can anyone shed some light on what is going on and why I continue to
get an instance of CParty and not CPartyGroup or CPerson.
Which kind of inheritance do you use? In OJB <=1.0.3 there is a bug in
retrieve objects using "Mapping Classes on Multiple Joined Tables"
(see release notes, it's fixed in CVS OJB_1_0_RELEASE branch).
> CParty party = (CParty) getBroker().getObjectByIdentity(oid);
This call should return the correct object instance, no need to query
with the correct partyIdType again.
Could you post the metadata mapping for Party, Person, PartyGroup?
Here is the mapping for the tree class. I solved my problem by removing
the <extent> tags from the party descriptor. You did mention that I
could do this in one query I an interested in knowing how.
<class-descriptor
class="net.enterprise.common.model.party.CParty"
proxy="dynamic"
table="party"
>
<field-descriptor
name="partyId"
column="party_id"
jdbc-type="integer"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="partyTypeId"
column="party_type_id"
jdbc-type="varchar"
/>
</class-descriptor>
<class-descriptor
class="net.enterprise.common.model.party.CPartyGroup"
proxy="dynamic"
table="party_group"
>
<field-descriptor
name="partyId"
column="party_id"
jdbc-type="integer"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="groupName"
column="group_name"
jdbc-type="varchar"
/>
<reference-descriptor name="super"
class-ref="net.enterprise.common.model.party.CParty"
auto-retrieve="true"
auto-update="true"
>
<foreignkey field-ref="partyId"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor
class="net.enterprise.common.model.party.CPerson"
proxy="dynamic"
table="person"
>
<field-descriptor
name="partyId"
column="party_id"
jdbc-type="integer"
primarykey="true"
/>
<field-descriptor
name="firstName"
column="first_name"
jdbc-type="varchar"
/>
<field-descriptor
name="middleName"
column="middle_name"
jdbc-type="varchar"
/>
<field-descriptor
name="lastName"
column="last_name"
jdbc-type="varchar"
/>
<reference-descriptor name="super"
class-ref="net.enterprise.common.model.party.CParty"
auto-retrieve="true"
auto-update="true"
auto-delete="true"
>
<foreignkey field-ref="partyId"/>
</reference-descriptor>
</class-descriptor>
regards,
Armin
// Find the party
Identity oid =
getBroker().serviceIdentity().buildIdentity(CParty.class, partyId);
CParty party = (CParty) getBroker().getObjectByIdentity(oid);
if (CParty.TYPE_PARTY_GROUP.equals(party.getPartyTypeId()))
{
// Get the Party Group
Identity partyGroupId =
getBroker().serviceIdentity().buildIdentity(CPartyGroup.class, partyId);
// ClastCastException here
CPartyGroup partyGroup = (CPartyGroup)
getBroker().getObjectByIdentity(partyGroupId);
setParameter("party", partyGroup);
}
else if (CParty.TYPE_PERSON.equals(party.getPartyTypeId()))
{
// Get the person
Identity personId =
getBroker().serviceIdentity().buildIdentity(CPerson.class, partyId);
// ClastCastException here
CPerson person = (CPerson) getBroker().getObjectByIdentity(personId);
setParameter("party", person);
}
else
{
setParameter("party", party);
}
-chris worley
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]