Hi, my answer is a little late for you : For count with a query, you have broker.getCount(query) It will make select count(*) from ... without using an iterator
Second thing for using iterator (you can have this problem later) : There is a big problem with Iterators, when you don't take all the lines of the iterator (you have 50 lines to get with your select but you stop at 30th line), you will have a problem with cursors in your database (in a moment, you'll have all yours cursors used and can't open a new cursor). For resolve this problem, you can use OJBIterator instead of Iterator (You cast the Iterator in OJBIterator), in the end of the method, you use releaseDbResources(), it will close the cursor from the database. -----Message d'origine----- De : Marco "Trink0" Trincardi [mailto:[EMAIL PROTECTED] Envoye : mardi 17 fevrier 2004 10:07 A : OJB Users List; [EMAIL PROTECTED] Objet : Re: Problem with Oracle9i and ReportQuery > Hi Marco, Hi Danilo, > do you iterate over the Iterator returned by > broker.getReportQueryIteratorByQuery(query) after > closing the broker? > (i do not see that from your code) > if yes, then you have to extract all data from the > Iterator before > closing the broker, otherwise the iterator will be > empty... You're right!!! My function returns the Iterator found with the getReportQuery function and i iterate over it in the caller. If i copy the content before closing the broker everithing works fine. What drove me nuts was that using HyperSqlDb (which is my development database, oracle9i is the production db) the iterator was Not empty after closing the broker. Just to satisfy my curiosity, anybody could explain why i have this (incorrect) behaviour in Hsqldb? Danilo, Thank u very much for your help Ciao Marco > > cheers > danilo > > > Hi all, > > > > in my application i'm using oracle9i & ojbrc4 and > i'm stucked with the > > following problem: > > I need to count how many records I have in a > table; to do that i've > > written this code: > > --------------------------- > > Iterator iter = null; > > Criteria criteria = buildCriteria(); > > try { > > tx = m_odmg.newTransaction(); > > tx.begin(); > > > > PersistenceBroker broker = ((HasBroker) > tx).getBroker(); > > ReportQueryByCriteria query = > QueryFactory.newReportQuery( > > PrestazioniEffettuateBO.class, > > criteria); > > > > query.setColumns(new String[] { > "count(*)", "id_user" }); > > query.addGroupBy("id_user"); > > > > iter = > broker.getReportQueryIteratorByQuery(query); > > tx.commit(); > > } catch (Exception ex) { > > .... > > } > > ------------------- > > which generates the following query (printed from > spy.log): > > ------------------- > > SELECT count(*),A0.ID_USER FROM > PRESTAZIONI_EFFETTUATE A0 > > WHERE ( (A0.ID_SCHEDE_POLIMORFICHE = '5' ) AND > > A0.ID_PRESTAZIONE = '1' ) AND (A0.STATO <> 'A' > OR (A0.STATO IS NULL )) > > GROUP BY A0.ID_USER > > ------------------- > > > > The problem is that the returned Iterator is empty > but if i run the > > query in the SQLPlus everthing works just fine!! > > > > The same code works perfectly using HSQLDB. > > > > I've searched the mailing list but i've found > nothing. > > Anybody could give me a hit? > > Is that a bug? > > I need to move to RC5? > > > > Thanx in advance > > > > Marco > > ------------------------------------- > > Marco Trincardi > > ------------------------------------- > > e-mail: [EMAIL PROTECTED] > > [EMAIL PROTECTED] > > Yahoo Messenger: iltrink0 > > ICQ Number: 7161369 > > ------------------------------------- > > "Coding Ain't Done 'Till All the > Tests Run" > > ------------------------------------- > > > > > > > > > --------------------------------------------------------------------- > > 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]
