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?
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]