Re: ClassCastException with getObjectByIdentity()

2005-11-29 Thread Armin Waibel

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  tags from the party descriptor.  


You are using "Mapping Classes on Multiple Joined Tables", thus you 
can't mix it with other inheritance strategies (e.g. using the 
extent-class element) and if you use OJB <=1.0.3, you will get the 
inheritance bug (see above).



You did mention that I 
could do this in one query I an interested in knowing how.




In the next version of OJB this will be fixed (or try the 
OJB_1_0_RELEASE branch from CVS) and

CParty party = (CParty) getBroker().getObjectByIdentity(oid);
will always return the correct object instance (CParty, CPartyGroup or 
Person) and you can directly cast to the real party type.


regards,
Armin




 
 
  


 
 
 
   
   
  


 
 
 
 
 
   
   
  





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]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ClassCastException with getObjectByIdentity()

2005-11-29 Thread Chris Worley

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  tags from the party descriptor.  You did mention that I 
could do this in one query I an interested in knowing how.



  
   
   name="partyId"
   column="party_id"
   jdbc-type="integer"
   primarykey="true"
   autoincrement="true"
   />
  
   
   name="partyTypeId"
   column="party_type_id"
   jdbc-type="varchar"
   />
  




  
   
   name="partyId"
   column="party_id"
   jdbc-type="integer"
   primarykey="true"
   autoincrement="true"
   />
  
   
   name="groupName"
   column="group_name"
   jdbc-type="varchar"
   />
  
   
   class-ref="net.enterprise.common.model.party.CParty"
   auto-retrieve="true"
   auto-update="true"
   >
   
   
  




  
   
   name="partyId"
   column="party_id"
   jdbc-type="integer"
   primarykey="true"
   />
  
   
   name="firstName"
   column="first_name"
   jdbc-type="varchar"
   />
  
   
   name="middleName"
   column="middle_name"
   jdbc-type="varchar"
   />
  
   
   name="lastName"
   column="last_name"
   jdbc-type="varchar"
   />
  
   
   class-ref="net.enterprise.common.model.party.CParty"
   auto-retrieve="true"
   auto-update="true"
   auto-delete="true"
   >
   
   
  







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]



Re: ClassCastException with getObjectByIdentity()

2005-11-29 Thread Chris Worley


I have found my problem.  I was using the  tag for in the 
descriptor for party referencing PartyGroup and Person.  After removing 
the extent the correct instance is returned.


-chris worley




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.



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



Re: ClassCastException with getObjectByIdentity()

2005-11-29 Thread Armin Waibel

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]



ClassCastException with getObjectByIdentity()

2005-11-29 Thread Chris Worley



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.



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