You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Jens Mayer <Je...@gmx.de> on 2008/08/06 12:35:19 UTC

SQLTemplate and setPageSize()

Hi,

i'm using Cayenne 2.0.4 with Oracle 10 and JDK 1.5.

Please have a short look at this code:

... dataCtx, myID are set... 

SQLTemplate rawQuery = (SQLTemplate)dataCtx.getEntityResolver().lookupQuery("myQuery");
Map<String,Object> params = new HashMap<String,Object>();
params.put("processID", myID);
rawQuery.setParameters(params);
rawQuery.setPageSize(50);
List<?> protList = dataCtx.performQuery(rawQuery);
...

On runtime the follwoing Exception ist thrown:

java.lang.IllegalArgumentException: org.apache.cayenne.query.SelectQuery: "setRoot(..)" takes a DataMap, String, ObjEntity, DbEntity, Procedure, or Class. It was passed a null
	at org.apache.cayenne.query.AbstractQuery.setRoot(AbstractQuery.java:104)
	at org.apache.cayenne.query.SelectQuery.init(SelectQuery.java:143)
	at org.apache.cayenne.query.SelectQuery.<init>(SelectQuery.java:83)
	at org.apache.cayenne.query.SelectQuery.<init>(SelectQuery.java:72)
	at org.apache.cayenne.access.IncrementalFaultList.<init>(IncrementalFaultList.java:129)
	at org.apache.cayenne.access.DataContextQueryAction.interceptPaginatedQuery(DataContextQueryAction.java:92)
	at org.apache.cayenne.access.DataContextQueryAction.execute(DataContextQueryAction.java:50)
	at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1395)
	at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1384)
        ..... more 

The mapped query is configured to fetch DataRows.

The cause seems to be the method setPageSize(): if I omit this method, all works fine. I cannot find any restrictions for setPageSize and SQLTemplate in the documentation.

Does anybody know what's going on here ? 

Thanks in advance

Jens
-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

Re: SQLTemplate and setPageSize()

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Aug 6, 2008, at 11:26 AM, Andrus Adamchik wrote:

> Not quite sure why the root is null.

Actually I have a few suspicions why this is happenning, and this may  
be a bug. Care to log a bug report in Jira?

    https://issues.apache.org/cayenne/


In the meantime you can use a workaround:

    localQuery.setRoot("MyEntity");

Andrus


Re: SQLTemplate and setPageSize()

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Jens,

Not quite sure why the root is null. So is named query mapped via the  
Modeler or do you add it in the code?

As an aside (this may have nothing to do with your problem), all  
mapped queries are shared across DataContexts, so you may have a race  
condition when you attempt to modify the query in the code. So you may  
want to clone the query like that:

SQLTemplate localQuery = rawQuery.queryWithParameters(...);
localQuery.setpageSize(50);

Andrus

On Aug 6, 2008, at 6:35 AM, Jens Mayer wrote:

> Hi,
>
> i'm using Cayenne 2.0.4 with Oracle 10 and JDK 1.5.
>
> Please have a short look at this code:
>
> ... dataCtx, myID are set...
>
> SQLTemplate rawQuery =  
> (SQLTemplate)dataCtx.getEntityResolver().lookupQuery("myQuery");
> Map<String,Object> params = new HashMap<String,Object>();
> params.put("processID", myID);
> rawQuery.setParameters(params);
> rawQuery.setPageSize(50);
> List<?> protList = dataCtx.performQuery(rawQuery);
> ...
>
> On runtime the follwoing Exception ist thrown:
>
> java.lang.IllegalArgumentException:  
> org.apache.cayenne.query.SelectQuery: "setRoot(..)" takes a DataMap,  
> String, ObjEntity, DbEntity, Procedure, or Class. It was passed a null
> 	at  
> org.apache.cayenne.query.AbstractQuery.setRoot(AbstractQuery.java:104)
> 	at org.apache.cayenne.query.SelectQuery.init(SelectQuery.java:143)
> 	at org.apache.cayenne.query.SelectQuery.<init>(SelectQuery.java:83)
> 	at org.apache.cayenne.query.SelectQuery.<init>(SelectQuery.java:72)
> 	at  
> org 
> .apache 
> .cayenne 
> .access.IncrementalFaultList.<init>(IncrementalFaultList.java:129)
> 	at  
> org 
> .apache 
> .cayenne 
> .access 
> .DataContextQueryAction 
> .interceptPaginatedQuery(DataContextQueryAction.java:92)
> 	at  
> org 
> .apache 
> .cayenne 
> .access.DataContextQueryAction.execute(DataContextQueryAction.java:50)
> 	at org.apache.cayenne.access.DataContext.onQuery(DataContext.java: 
> 1395)
> 	at  
> org.apache.cayenne.access.DataContext.performQuery(DataContext.java: 
> 1384)
>        ..... more
>
> The mapped query is configured to fetch DataRows.
>
> The cause seems to be the method setPageSize(): if I omit this  
> method, all works fine. I cannot find any restrictions for  
> setPageSize and SQLTemplate in the documentation.
>
> Does anybody know what's going on here ?
>
> Thanks in advance
>
> Jens
> -- 
> Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
> Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
>