I think that it is a valid way of constructing a query. As I understand, one
should be able to nest a ReportQueryByCriteria within a QueryByCriteria as
long as the nested report query selects only one attribute.

So, yes. I think that this is accurately reproducing the problem.

Regards,

Joshua Phillips
Contractor (SAIC)
Tel: 301 451 6346
Fax: 301 480 4222
[EMAIL PROTECTED] 

> -----Original Message-----
> From: Armin Waibel [mailto:[EMAIL PROTECTED]
> Sent: Monday, August 23, 2004 7:23 AM
> To: OJB Users List
> Subject: Re: SqlQueryStatement.splitCriteria -> NullPointerException
> 
> Hi,
> 
> I think my test was too simple to reproduce your problem. I modified
> QueryTest#testReportQueryExtent and do the query against an abstract
> class. This test pass. But you additionally do a sub-Query.
> Modified my test again and now I can reproduce your problem:
> 
> Criteria critMain = new Criteria();
> Criteria critSub = new Criteria();
> 
> critSub.addLike("articleName", "%o%");
> ReportQueryByCriteria querySub =
> QueryFactory.newReportQuery(AbstractArticle.class, critSub);
> querySub.setAttributes(new String[] { "articleId"});
> 
> critMain.addIn("productGroup.groupId", querySub);
> ReportQueryByCriteria queryMain =
> QueryFactory.newReportQuery(AbstractProductGroup.class, critMain);
> 
> Iterator iter = broker.getReportQueryIteratorByQuery(queryMain);
> 
> The query itself doesn't make any sense I only want to provoke the NPE.
> 
> This test cause an NPE:
> 
> testReportQueryAbstractClassWithExtent(org.apache.ojb.broker.QueryTest)jav
> a.lang.NullPointerException
>       at
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias.hashCod
> e(SqlQueryStatement.java:1974)
>       at java.util.HashMap.hash(HashMap.java:261)
>       at java.util.HashMap.put(HashMap.java:379)
>       at
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.splitCriteria(SqlQ
> ueryStatement.java:1683)
>       at
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.<init>(SqlQuerySta
> tement.java:132)
> 
> 
> I'm not really familiar with the PB-query generation, so is this query
> valid and does it reproduce your problem?
> 
> regards,
> Armin
> 
> 
> Phillips, Joshua (NIH/NCI) wrote:
> 
> > Hi Armin,
> >
> > Thanks for taking the time to write a test.
> >
> > BaseInterface is just an interface. So, it declares only BaseImpl as an
> > extent-class. BaseImpl declares all attributes (include
> ojbConcreteClass)
> > and associations. It also declares AImpl as an extent class.
> >
> > Could you please email me that test-case, or at least a snippet. Maybe
> I'm
> > missing something.
> >
> > Thanks again.
> >
> > Joshua Phillips
> > Contractor (SAIC)
> > Tel: 301 451 6346
> > Fax: 301 480 4222
> > [EMAIL PROTECTED]
> >
> >
> >>-----Original Message-----
> >>From: Armin Waibel [mailto:[EMAIL PROTECTED]
> >>Sent: Saturday, August 21, 2004 6:21 AM
> >>To: OJB Users List
> >>Subject: Re: SqlQueryStatement.splitCriteria -> NullPointerException
> >>
> >>Hi Jakob, Joshua,
> >>
> >>made a test with a modified version of QueryTest#testReportQueryExtent
> >>against AbstractArticle.class. This test pass. Maybe BaseInterface.class
> >>  did not declare extents in repository?
> >>
> >>regards,
> >>Armin
> >>
> >>J.Braeuchi wrote:
> >>
> >>>hi joshua,
> >>>
> >>>what version of ojb are you using ?
> >>>is it ok to use hashcode 0 if no table is available.
> >>>
> >>>jakob
> >>>
> >>>Phillips, Joshua (NIH/NCI) schrieb:
> >>>
> >>>
> >>>>The collection-descriptor for an abstract class does not have a table
> >>>>attribute. So, when SqlQueryStatement.splitCriteria is called, a
> >>>>NullPointerException is thrown when it tries to put the root
> >>>>TableAlias into
> >>>>the m_jointTreeToCriteria HashMap, because
> >>>>SqlQueryStatement.TableAlias.hashCode looks like this:
> >>>>
> >>>>        public int hashCode() {
> >>>>            return table.hashCode();
> >>>>        }
> >>>>
> >>>>...and table is null.
> >>>>
> >>>>The code that I used to produce this error looks like this:
> >>>>
> >>>>PersistenceBroker pb = PersistenceBrokerFactory
> >>>>    .defaultPersistenceBroker();
> >>>>Criteria subCrit = new Criteria();
> >>>>subCrit.addEqualTo("id", new Long(1));
> >>>>ReportQueryByCriteria assocPBQ = QueryFactory.newReportQuery(
> >>>>    BaseInterface.class, subCrit);
> >>>>assocPBQ.setAttributes(new String[] { "id" });
> >>>>Criteria crit = new Criteria();
> >>>>crit.addIn("base.id", assocPBQ);
> >>>>QueryByCriteria q = (QueryByCriteria) QueryFactory.newQuery(
> >>>>    BaseAssocInterface.class, crit, true);
> >>>>Collection c = pb.getCollectionByQuery(q);
> >>>>
> >>>>The stack trace looks like this:
> >>>>
> >>>>Caused by: java.lang.NullPointerException
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias.hashC
> od
> >>e(
> >>
> >>>>Unknown Source)
> >>>>    at java.util.HashMap.hash(HashMap.java:261)
> >>>>    at java.util.HashMap.put(HashMap.java:379)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.splitCriteria(Un
> kn
> >>ow
> >>
> >>>>n Source)
> >>>>    at
> >>>>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.<init>(Unknown
> >>>>Source)
> >>>>    at
> >>>>org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.<init>(Unknow
> n
> >>>>Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getSubQuerySQL(U
> nk
> >>no
> >>
> >>>>wn Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSubQuery(U
> nk
> >>no
> >>
> >>>>wn Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendParameter(
> Un
> >>kn
> >>
> >>>>own Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendInCriteria
> (U
> >>nk
> >>
> >>>>nown Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(U
> nk
> >>no
> >>
> >>>>wn Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(
> Un
> >>kn
> >>
> >>>>own Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(U
> nk
> >>no
> >>
> >>>>wn Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unk
> no
> >>wn
> >>
> >>>>Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClaus
> e(
> >>Un
> >>
> >>>>known Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Un
> kn
> >>ow
> >>
> >>>>n Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPrepare
> dS
> >>el
> >>
> >>>>ectStatement(Unknown Source)
> >>>>    at
> >>>>org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown
> >>>>Source)
> >>>>    at
> >>>>org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(Unknown
> >>>>Source)
> >>>>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown
> >>>>Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknow
> n
> >>
> >>>>Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(
> Un
> >>kn
> >>
> >>>>own Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Un
> kn
> >>ow
> >>
> >>>>n Source)
> >>>>    at
> >>>>
> >>
> >>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk
> no
> >>wn
> >>
> >>>>Source)
> >>>>    ... 20 more
> >>>>
> >>>>Joshua Phillips
> >>>>Contractor (SAIC)
> >>>>Tel: 301 451 6346
> >>>>Fax: 301 480 4222
> >>>>[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]

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

Reply via email to