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/03/01 09:49:38 UTC

Criteria.setClassPath - the saga continues

Hi all,

Following my query last week, I've botched my query to use the
ojbConcreteClass directly. I now have a problem that the generated SQL for
the following sample is incorrect :

Criteria criteria1 = new Criteria();
criteria1.addEqualTo("outPayment.agreement.ojbConcreteClass",
"aquarius.agreement.ServiceAgreement");
criteria1.addEqualTo("outPayment.agreement.clientNumber", "0000001");

QueryByCriteria query = QueryFactory.newQuery(OutPaymentDestination.class,
criteria1);
query.addPathClass("outPayment.agreement", ServiceAgreement.class);

PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
Collection results = pb.getCollectionByQuery(query);


Generated SQL :
	SELECT [... a load of attributes] FROM OUTPAYMENTDESTINATION A0 
		INNER JOIN OUTPAYMENT A1 ON A0.OUTPAYMENTID=A1.ID 
		INNER JOIN AGREEMENT A2 ON A1.AGREEMENTID=A2.ID 
	WHERE (A2.OJBCONCRETECLASS =  ? ) AND clientNumber =  ?

the corrext SQL should have (I think) been 

	SELECT [... a load of attributes] FROM OUTPAYMENTDESTINATION A0 
		INNER JOIN OUTPAYMENT A1 ON A0.OUTPAYMENTID=A1.ID 
		INNER JOIN AGREEMENT A2 ON A1.AGREEMENTID=A2.ID 
	WHERE (A2.OJBCONCRETECLASS =  ? ) AND (A2.CLIENTNUMBER =  ?)

One Outpayment has many OutPaymentDestinations.
One Agreement has many OutPayments
A ServiceAgreement is a subclass of Agreement
All agreements are mapped to the AGREEMENT table.

The clientNumber attribute is only available on ServiceAgreement (and maps
to the CLIENTNUMBER attribute on the AGREEMENT table). 


We want to do a query for all outpaymentdestinations for a ServiceAgreement
with a client number of "0000001".

The path class hint is being used to pick the right table up, but it seems
to fail on looking up up the column name, so that the un-qualified attribute
name is added to the query. 

Please Help !

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.setClassPath - the saga continues

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

i checked the testcase dealing with setPathClass. they all work with single 
segment path only.
have you tried to debug the problem ?

jakob

Charles Anthony wrote:

> Hi all,
> 
> Following my query last week, I've botched my query to use the
> ojbConcreteClass directly. I now have a problem that the generated SQL for
> the following sample is incorrect :
> 
> Criteria criteria1 = new Criteria();
> criteria1.addEqualTo("outPayment.agreement.ojbConcreteClass",
> "aquarius.agreement.ServiceAgreement");
> criteria1.addEqualTo("outPayment.agreement.clientNumber", "0000001");
> 
> QueryByCriteria query = QueryFactory.newQuery(OutPaymentDestination.class,
> criteria1);
> query.addPathClass("outPayment.agreement", ServiceAgreement.class);
> 
> PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
> Collection results = pb.getCollectionByQuery(query);
> 
> 
> Generated SQL :
> 	SELECT [... a load of attributes] FROM OUTPAYMENTDESTINATION A0 
> 		INNER JOIN OUTPAYMENT A1 ON A0.OUTPAYMENTID=A1.ID 
> 		INNER JOIN AGREEMENT A2 ON A1.AGREEMENTID=A2.ID 
> 	WHERE (A2.OJBCONCRETECLASS =  ? ) AND clientNumber =  ?
> 
> the corrext SQL should have (I think) been 
> 
> 	SELECT [... a load of attributes] FROM OUTPAYMENTDESTINATION A0 
> 		INNER JOIN OUTPAYMENT A1 ON A0.OUTPAYMENTID=A1.ID 
> 		INNER JOIN AGREEMENT A2 ON A1.AGREEMENTID=A2.ID 
> 	WHERE (A2.OJBCONCRETECLASS =  ? ) AND (A2.CLIENTNUMBER =  ?)
> 
> One Outpayment has many OutPaymentDestinations.
> One Agreement has many OutPayments
> A ServiceAgreement is a subclass of Agreement
> All agreements are mapped to the AGREEMENT table.
> 
> The clientNumber attribute is only available on ServiceAgreement (and maps
> to the CLIENTNUMBER attribute on the AGREEMENT table). 
> 
> 
> We want to do a query for all outpaymentdestinations for a ServiceAgreement
> with a client number of "0000001".
> 
> The path class hint is being used to pick the right table up, but it seems
> to fail on looking up up the column name, so that the un-qualified attribute
> name is added to the query. 
> 
> Please Help !
> 
> 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


Re: Criteria.setClassPath - the saga continues

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

i think i found the problem with the multi-segment path:

in SqlQueryStatement#getTableAlias there are two locations calling 
getItemClassDescriptor:

                 cld = getItemClassDescriptor(ord, attr);

the argument attr contains the last segment of the path only. change these lines to:

                 cld = getItemClassDescriptor(ord, attrPath);

this should imo work.
please tell me whether it solves your problem.

jakob


Charles Anthony wrote:

> Hi all,
> 
> Following my query last week, I've botched my query to use the
> ojbConcreteClass directly. I now have a problem that the generated SQL for
> the following sample is incorrect :
> 
> Criteria criteria1 = new Criteria();
> criteria1.addEqualTo("outPayment.agreement.ojbConcreteClass",
> "aquarius.agreement.ServiceAgreement");
> criteria1.addEqualTo("outPayment.agreement.clientNumber", "0000001");
> 
> QueryByCriteria query = QueryFactory.newQuery(OutPaymentDestination.class,
> criteria1);
> query.addPathClass("outPayment.agreement", ServiceAgreement.class);
> 
> PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
> Collection results = pb.getCollectionByQuery(query);
> 
> 
> Generated SQL :
> 	SELECT [... a load of attributes] FROM OUTPAYMENTDESTINATION A0 
> 		INNER JOIN OUTPAYMENT A1 ON A0.OUTPAYMENTID=A1.ID 
> 		INNER JOIN AGREEMENT A2 ON A1.AGREEMENTID=A2.ID 
> 	WHERE (A2.OJBCONCRETECLASS =  ? ) AND clientNumber =  ?
> 
> the corrext SQL should have (I think) been 
> 
> 	SELECT [... a load of attributes] FROM OUTPAYMENTDESTINATION A0 
> 		INNER JOIN OUTPAYMENT A1 ON A0.OUTPAYMENTID=A1.ID 
> 		INNER JOIN AGREEMENT A2 ON A1.AGREEMENTID=A2.ID 
> 	WHERE (A2.OJBCONCRETECLASS =  ? ) AND (A2.CLIENTNUMBER =  ?)
> 
> One Outpayment has many OutPaymentDestinations.
> One Agreement has many OutPayments
> A ServiceAgreement is a subclass of Agreement
> All agreements are mapped to the AGREEMENT table.
> 
> The clientNumber attribute is only available on ServiceAgreement (and maps
> to the CLIENTNUMBER attribute on the AGREEMENT table). 
> 
> 
> We want to do a query for all outpaymentdestinations for a ServiceAgreement
> with a client number of "0000001".
> 
> The path class hint is being used to pick the right table up, but it seems
> to fail on looking up up the column name, so that the un-qualified attribute
> name is added to the query. 
> 
> Please Help !
> 
> 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