Jakob,

Ok, I miss understood its purpose. I wanted and instance of PhoneNumber or PostalAddress, I guess it goes back to the bug Armin mentioned. I have modified my code to loop through the results and query for the appropriate table and set it in PartyContactMech.

Thanks for the clarification. I see now in the example that it is referencing a field in the extended table.

-chris worley

hi chris,

adding a path class makes only sense when you hava a path in your query.

ie:
crit.addEqualTo("contactMech.something", on other thing);
crit.addPathClass("contactMech", CPhoneNumber.class);

jakob

Chris Worley schrieb:

Jakob,


-- with hints and extents defined for CContactMech

Integer partyId = (Integer) getParameter("partyId");
Criteria crit = new Criteria();
crit.addEqualTo("partyId", partyId);
crit.addPathClass("contactMech", CPhoneNumber.class);
      Criteria critAddress = new Criteria();
critAddress.addEqualTo("partyId", partyId);
critAddress.addPathClass("contactMech", CPostalAddress.class);
      crit.addOrCriteria(critAddress);
Query query = QueryFactory.newQuery(CPartyContactMech.class, crit);
Collection partyContactMechs = getBroker().getCollectionByQuery(query);


[org.apache.ojb.broker.core.QueryReferenceBroker] DEBUG: getCollectionByQuery (class org.apache.ojb.broker.util.collections.RemovalAwareCollection, class net.enterprise.common.model.party.CPartyContactMech, QueryByCriteria from class net.enterprise.common.model.party.CPartyContactMech where [partyId = 1, [partyId = 1]]) [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.party_contact_mech_id,A0.party_id,A0.contact_mech_id,A0.from_date,A0.thru_date,A0.contact_mech_purpose_id FROM party_contact_mech A0 WHERE A0.party_id = ? OR (A0.party_id = ?) [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.contact_mech_id,A0.contact_mech_type_id FROM contact_mech A0 WHERE A0.contact_mech_id = ? [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.contact_mech_id,A0.country_code,A0.area_code,A0.contact_number FROM phone_number A0 INNER JOIN contact_mech A1 ON A0.contact_mech_id=A1.contact_mech_id WHERE A0.contact_mech_id = ? [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.contact_mech_id,A0.to_name,A0.attention,A0.address1,A0.address2,A0.city,A0.postal_code,A0.state_geo_id,A0.country_geo_id FROM postal_address A0 INNER JOIN contact_mech A1 ON A0.contact_mech_id=A1.contact_mech_id WHERE A0.contact_mech_id = ? [org.apache.ojb.broker.cache.MaterializationCache] DEBUG: Materialisation of object is finished, push 2objects to cache [org.apache.ojb.broker.cache.MaterializationCache] DEBUG: Push to cache: net.enterprise.common.model.party.CPartyContactMech{1} [org.apache.ojb.broker.cache.MaterializationCache] DEBUG: Push to cache: net.enterprise.common.model.contact.CContactMech{2}

-- without hints and extents defined for CContactMech


Integer partyId = (Integer) getParameter("partyId");
Criteria crit = new Criteria();
crit.addEqualTo("partyId", partyId);
     Query query = QueryFactory.newQuery(CPartyContactMech.class, crit);
Collection partyContactMechs = getBroker().getCollectionByQuery(query);


[org.apache.ojb.broker.core.QueryReferenceBroker] DEBUG: getCollectionByQuery (class org.apache.ojb.broker.util.collections.RemovalAwareCollection, class net.enterprise.common.model.party.CPartyContactMech, QueryByCriteria from class net.enterprise.common.model.party.CPartyContactMech where [partyId = 1]) [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.party_contact_mech_id,A0.party_id,A0.contact_mech_id,A0.from_date,A0.thru_date,A0.contact_mech_purpose_id FROM party_contact_mech A0 WHERE A0.party_id = ? [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.contact_mech_id,A0.contact_mech_type_id FROM contact_mech A0 WHERE A0.contact_mech_id = ? [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.contact_mech_id,A0.country_code,A0.area_code,A0.contact_number FROM phone_number A0 INNER JOIN contact_mech A1 ON A0.contact_mech_id=A1.contact_mech_id WHERE A0.contact_mech_id = ? [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias] DEBUG: TableAlias(): using hints ? false [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.contact_mech_id,A0.to_name,A0.attention,A0.address1,A0.address2,A0.city,A0.postal_code,A0.state_geo_id,A0.country_geo_id FROM postal_address A0 INNER JOIN contact_mech A1 ON A0.contact_mech_id=A1.contact_mech_id WHERE A0.contact_mech_id = ? [org.apache.ojb.broker.cache.MaterializationCache] DEBUG: Materialisation of object is finished, push 2objects to cache [org.apache.ojb.broker.cache.MaterializationCache] DEBUG: Push to cache: net.enterprise.common.model.party.CPartyContactMech{1} [org.apache.ojb.broker.cache.MaterializationCache] DEBUG: Push to cache: net.enterprise.common.model.contact.CContactMech{2}


-chris worley

hi chris,

please post the sql with and without the hints.

jakob

Chris Worley schrieb:



Actually I don't think this problem is directly related to class hints. In a previous thread Armin mentioned to me that there was a but that will be fixed in the next released

previouse email from Armin:
> 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.

-chris worley


I am having a problem with class hints. They do not seem to work all the time with my configuration. If the PartyContactMech object is stored in the same instance of the server process that I retreive it in PartyContactMech.contactMech is populated with an instance of CPhoneNumber or CPostalAddress. If I try to reteive a records that were created in a previous instance of the process then PartyContactMech.contactMechs is populated with an instance of ContactMech.


Integer partyId = (Integer) getParameter("partyId");
Criteria crit = new Criteria();
crit.addEqualTo("partyId", partyId);
crit.addPathClass("contactMech", CPhoneNumber.class);
      Criteria critAddress = new Criteria();
critAddress.addEqualTo("partyId", partyId);
critAddress.addPathClass("contactMech", CPostalAddress.class);
      crit.addOrCriteria(critAddress);
Query query = QueryFactory.newQuery(CPartyContactMech.class, crit); Collection partyContactMechs = getBroker().getCollectionByQuery(query);
setParameter("partyContactMechs", partyContactMechs);


<class-descriptor
       class="net.enterprise.common.model.contact.CContactMech"
       table="contact_mech"
   >
<extent-class class-ref="net.enterprise.common.model.contact.CPhoneNumber"/> <extent-class class-ref="net.enterprise.common.model.contact.CPostalAddress"/>
     <field-descriptor
           name="contactMechId"
           column="contact_mech_id"
           jdbc-type="integer"
           primarykey="true"
           autoincrement="true"
       />
     <field-descriptor
           name="contactMechTypeId"
           column="contact_mech_type_id"
           jdbc-type="varchar"
       />
  </class-descriptor>


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

.


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

Reply via email to