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 Charles Anthony <ch...@hpdsoftware.com> on 2004/02/26 13:43:07 UTC

Criteria.setPathClass - doesn't use OJBCONCRETECLASS in query

Hi All,

I think I have a possible bug.

TermsOfAgreement has an association with Agreement (1:1, in this case,
although this problem arise in other places with 1:n relationships).

TermsOfAgreement maps to TERMSOFAGREEMNT
Agreement maps to table  AGREEMENT

Agreement has many subclasses/extents , all mapped to the same AGREEMENT.

The following query should get TermsOfAgreement for all Agreements with a
client number beginning with 0 :

	Criteria criteria = new Criteria();
	criteria.addLike("agreement.clientNumber","0%");
	QueryByCriteria qbc = new QueryByCriteria(TermsOfAgreement.class,
criteria);

I believe that I should be able to do
	
	qbc.setPathClass("agreement", DebtorAccount.class);

to get all TermsOfAgreement for all DebtorAccount with a client number
beginning with 0. DebtorAccount is a subclass of Agreement.

Unfortunately, it returns the same result as before i.e. all agreements.

The ojbConcreteClass attribute is correctly set (I can do a query for all
DebtorAccounts successfully).

Looking at the generated SQL, the hint does not affect the generated sql. If
I turn logging on for 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement, I get the following
without the hint

2004-02-26 12:20:05,606 [main] DEBUG sql.SqlQueryStatement$TableAlias -
TableAlias(): using hints ? false
2004-02-26 12:20:05,621 [main] DEBUG sql.SqlQueryStatement$TableAlias -
TableAlias(): using hints ? false
2004-02-26 12:20:05,637 [main] DEBUG sql.SqlGeneratorDefaultImpl    -
SQL:SELECT
A0.AGREEMENTID,A0.OPTIMISTICLOCK,A0.AGREEMENTTYPEID,A0.CURRENCYID,A0.ID FROM
TERMSOFAGREEMENT A0 INNER JOIN AGREEMENT A1 ON A0.AGREEMENTID=A1.ID WHERE
clientNumber LIKE  ?

and the following WITH the hint

2004-02-26 12:20:06,825 [main] DEBUG sql.SqlQueryStatement$TableAlias -
TableAlias(): using hints ? false
2004-02-26 12:20:06,825 [main] DEBUG sql.SqlQueryStatement$TableAlias -
TableAlias(): using hints ? true
2004-02-26 12:20:06,840 [main] DEBUG sql.SqlGeneratorDefaultImpl    -
SQL:SELECT
A0.AGREEMENTID,A0.OPTIMISTICLOCK,A0.AGREEMENTTYPEID,A0.CURRENCYID,A0.ID FROM
TERMSOFAGREEMENT A0 INNER JOIN AGREEMENT A1 ON A0.AGREEMENTID=A1.ID WHERE
A1.CLIENTNUMBER LIKE  ? 


i.e. No Change.

I imagined it would do SQL:SELECT
A0.AGREEMENTID,A0.OPTIMISTICLOCK,A0.AGREEMENTTYPEID,A0.CURRENCYID,A0.ID FROM
TERMSOFAGREEMENT A0 INNER JOIN AGREEMENT A1 ON A0.AGREEMENTID=A1.ID WHERE
A1.CLIENTNUMBER LIKE  ? AND A1.OJBCONCRETECLASS LIKE ?

Am I doing something wrong ?

Currently, we've botched the query by using the ojbConcreteClass attribute
directly in the query. I'd really rather not.

First spotted this in rc4, quickly re-tested in rc5 to see if it had been
spotted, no difference.

Cheers,

Charles.


___________________________________________________________
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Criteria.setPathClass - doesn't use OJBCONCRETECLASS in query

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi charles,

yes this is a problem. ojb only uses OJBCONCRETECLASS when building the query 
looking for an object mapped to a multi-mapped table.
this is also the reason why we cannot mix mapping-strategies within the 
hierarchy, see:

http://nagoya.apache.org/scarab/issues/id/OJB179

jakob

Charles Anthony wrote:

> Hi All,
> 
> I think I have a possible bug.
> 
> TermsOfAgreement has an association with Agreement (1:1, in this case,
> although this problem arise in other places with 1:n relationships).
> 
> TermsOfAgreement maps to TERMSOFAGREEMNT
> Agreement maps to table  AGREEMENT
> 
> Agreement has many subclasses/extents , all mapped to the same AGREEMENT.
> 
> The following query should get TermsOfAgreement for all Agreements with a
> client number beginning with 0 :
> 
> 	Criteria criteria = new Criteria();
> 	criteria.addLike("agreement.clientNumber","0%");
> 	QueryByCriteria qbc = new QueryByCriteria(TermsOfAgreement.class,
> criteria);
> 
> I believe that I should be able to do
> 	
> 	qbc.setPathClass("agreement", DebtorAccount.class);
> 
> to get all TermsOfAgreement for all DebtorAccount with a client number
> beginning with 0. DebtorAccount is a subclass of Agreement.
> 
> Unfortunately, it returns the same result as before i.e. all agreements.
> 
> The ojbConcreteClass attribute is correctly set (I can do a query for all
> DebtorAccounts successfully).
> 
> Looking at the generated SQL, the hint does not affect the generated sql. If
> I turn logging on for 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement, I get the following
> without the hint
> 
> 2004-02-26 12:20:05,606 [main] DEBUG sql.SqlQueryStatement$TableAlias -
> TableAlias(): using hints ? false
> 2004-02-26 12:20:05,621 [main] DEBUG sql.SqlQueryStatement$TableAlias -
> TableAlias(): using hints ? false
> 2004-02-26 12:20:05,637 [main] DEBUG sql.SqlGeneratorDefaultImpl    -
> SQL:SELECT
> A0.AGREEMENTID,A0.OPTIMISTICLOCK,A0.AGREEMENTTYPEID,A0.CURRENCYID,A0.ID FROM
> TERMSOFAGREEMENT A0 INNER JOIN AGREEMENT A1 ON A0.AGREEMENTID=A1.ID WHERE
> clientNumber LIKE  ?
> 
> and the following WITH the hint
> 
> 2004-02-26 12:20:06,825 [main] DEBUG sql.SqlQueryStatement$TableAlias -
> TableAlias(): using hints ? false
> 2004-02-26 12:20:06,825 [main] DEBUG sql.SqlQueryStatement$TableAlias -
> TableAlias(): using hints ? true
> 2004-02-26 12:20:06,840 [main] DEBUG sql.SqlGeneratorDefaultImpl    -
> SQL:SELECT
> A0.AGREEMENTID,A0.OPTIMISTICLOCK,A0.AGREEMENTTYPEID,A0.CURRENCYID,A0.ID FROM
> TERMSOFAGREEMENT A0 INNER JOIN AGREEMENT A1 ON A0.AGREEMENTID=A1.ID WHERE
> A1.CLIENTNUMBER LIKE  ? 
> 
> 
> i.e. No Change.
> 
> I imagined it would do SQL:SELECT
> A0.AGREEMENTID,A0.OPTIMISTICLOCK,A0.AGREEMENTTYPEID,A0.CURRENCYID,A0.ID FROM
> TERMSOFAGREEMENT A0 INNER JOIN AGREEMENT A1 ON A0.AGREEMENTID=A1.ID WHERE
> A1.CLIENTNUMBER LIKE  ? AND A1.OJBCONCRETECLASS LIKE ?
> 
> Am I doing something wrong ?
> 
> Currently, we've botched the query by using the ojbConcreteClass attribute
> directly in the query. I'd really rather not.
> 
> First spotted this in rc4, quickly re-tested in rc5 to see if it had been
> spotted, no difference.
> 
> Cheers,
> 
> Charles.
> 
> 
> ___________________________________________________________
> HPD Software Ltd. - Helping Business Finance Business
> Email terms and conditions: www.hpdsoftware.com/disclaimer 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org