You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Michael Dick <mi...@gmail.com> on 2009/11/17 19:23:51 UTC

Re: noob: NoSuchElementException when using FetchBatchSize

Hi Christopher,

Looks like the EntityManager has been closed before you iterated over the
list.

The FetchBatchSize parameter controls how many rows are fetched with
OpenJPA's Large ResultSet function. This works by using a scrollable
ResultSet, and paging over the results. As a side effect the connection
needs to remain open so we can load the next n results (where n = your
fetchBatchSize).

If you close the EntityManager the connection is closed with it and you
won't be able to iterate over the result list, or get the size of the result
list (which is what you're hitting).

At the moment this is a restriction when using Large ResultSets. There may
be some changes coming, but in order to support JEE containers pooling the
EntityManager instances it may become more restrictive rather than less..

Hope this helps
-mike

On Thu, Oct 29, 2009 at 4:23 PM, Christopher Giblin <CG...@zurich.ibm.com>wrote:

>
> Hi,
> I have OpenJPA 1.2.1, Derby 10.3 and deal with large result sets.  When I
> configure openjpa.FetchBatchSize to any number, 0, 1000, whatever, I get
> the following exception:
>
> java.util.NoSuchElementException: The result list has been closed.
>      at org.apache.openjpa.lib.rop.AbstractResultList.assertOpen(
> AbstractResultList.java:89)
>      at org.apache.openjpa.lib.rop.WindowResultList.size(
> WindowResultList.java:84)
>      at org.apache.openjpa.kernel.DelegatingResultList.size(
> DelegatingResultList.java:136)
>      at com.ibm.xxxx.SomeClass.test(SomeClass.java:30)
>
> Here are the persistence.xml properties:
>
> <properties>
>      <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
>      <property name="openjpa.ConnectionDriverName"     value=
> "org.apache.derby.jdbc.ClientDriver"/>
>      <property name="openjpa.ConnectionUserName"       value="abc"/>
>      <property name="openjpa.ConnectionPassword"       value="123"/>
>      <property name="openjpa.ConnectionRetainMode"     value="always"/>
>      <property name="openjpa.jdbc.DBDictionary"        value=
> "batchLimit=200"/>
>      <property name="openjpa.FetchBatchSize"           value="0"/>
>      <property name="openjpa.jdbc.ResultSetType"
> value="scroll-sensitive"/>
>      <property name="openjpa.jdbc.LRSSize"             value="last"/>
>      <property name="openjpa.Log" value="SQL=TRACE"/>
> </properties>
>
>
> I have tried various combinations of the properties, but always get the
> exception once FetchBatchSize is used.
>
> How can I avoid this exception?
>
> Thanks, chris
>
>