Hi Guarav,

Weird! Which database are you using?

We had similar problems, on Oracle9i. MySQL works fine in this issue.

1. Ask for an Iterator from PB.
2. Close PB.
3. Call iter.hasNext(), returns true.
4. Call iter.next(), get NoSuchElementException.

Turn out that, calling broker.close() will release the underlying database
resources, hence we get exception when iterating the Iterator.

The workaround we did is to move broker.close() after iterating is done.


Regards,
Lee Haw

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 24, 2002 12:59 PM
> To: [EMAIL PROTECTED]
> Subject: RE: Iterator Problem : Please help
>
>
> After spending a few hours, I found that this was a problem with
> the version
> of java that my web server was using. I upgraded from 1.2.2 to
> 1.3.1_06 and
> it worked like a charm.
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Monday, December 23, 2002 4:41 PM
> To: [EMAIL PROTECTED]
> Subject: Iterator Problem : Please help
>
>
> Please help with this:
> I'm getting the following error when I call next() on Iterator. However
> hasNext() returns true. if I do a getCount on broker, then it correctly
> returns the number of records. Any idea what the problem here could be?
> Thanks,
> Gaurav
>
> ----------------------------------------EXCEPTION-----------------
> ----------
> -----------------------------------------
>
> [23/Dec/2002:16:19:53] failure (  526): Internal error: exception thrown
> from the servlet service function (uri=/ojb/test.do):
> java.util.NoSuchElementException, Stack: java.util.NoSuchElementException
>       at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown Source)
>       at
> org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollection
> ByQuery(Un
> known Source)
>       at
> org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollection
> ByQuery(Un
> known Source)
>       at
> org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollection
> ByQuery(Un
> known Source)
>       at
> org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollection
> ByQuery(Un
> known Source)
>       at
> org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.getColl
> ectionByQu
> ery(Unknown Source)
>       at
> com.gecapital.erc.phoenix.test.TestServlet.getTableIterator(Unknow
> n Source)
>       at com.gecapital.erc.phoenix.test.TestServlet.doGet(Unknown Source)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at
> com.iplanet.server.http.servlet.NSServletRunner.invokeServletServi
> ce(NSServl
> etRunner.java:897)
>       at
> com.iplanet.server.http.servlet.WebApplication.service(WebApplicat
> ion.java:1
> 059)
>       at
> com.iplanet.server.http.servlet.NSServletRunner.ServiceWebApp(NSSe
> rvletRunne
> r.java:959)
>
> -------------------------------------------CODE-------------------
> ----------
> -------------------------------------
>
>     protected Iterator getTableIterator() throws IOException
>     {
>         Iterator result = null;
>               Collection cresult = null;
>         PersistenceBroker broker = null;
>         try
>         {
>               broker = getBroker();
>         }
>         catch (Exception ex)
>         {
>               throw new IOException(ex.getMessage());
>         }
>         Criteria selectAll = null;
>         Query query = QueryFactory.newQuery(MBudget.class, selectAll);
>         cresult = broker.getCollectionByQuery(query);
>               result = cresult.iterator();
>
> //this.getServletContext().log(Integer.toString(broker.getCount(query)));
>               broker.close();
>       return result;
>     }
>
>     protected void writeTable(Iterator iter, PrintWriter writer)
>     {
>         writer.println("<table border=\"1\">");
>         writer.println("<tr><td><b>ID</b></td></tr>");
>         while (iter.hasNext())
>         {
>               MBudget a = (MBudget) iter.next();
>               writer.println("<tr><td>" + a.getbudget_id() + "</td>
> </tr>");
>                       writer.println("<tr><td>aaa</td> </tr>");
>         }
>         writer.println("</table>");
>
>     }
>
>
> The iter.next() fails with NoSuchElementException
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>


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

Reply via email to