-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: count number of records in file (sql count)
PostPosted: Wed Feb 14, 2007 3:05 am 
Newbie

Joined: Wed Feb 14, 2007 2:51 am
Posts: 2
s it possible to get the count of the records in the table ?
one of my files is having more than 100,000 records and i want to show the total count to the user. When I make the select I get heap error (out of memory space errror) for more than 100,000 records

here is the code, i had to put the setMaxResults to avoid the memory error, but what I also need is the total count of records in the file

public Newsletter[] getAllCustomers()
{

List customers = new ArrayList();
List allnewsletter = new ArrayList();


Transaction tx = null;
Session session = HibernateSessionFactory.getSession();
session.beginTransaction();
Criteria criteria = session.createCriteria(Newsletter.class);
int size = criteria.list().size();
// here i get heap error but i need to get the total count
criteria.setMaxResults(1000);
allnewsletter = criteria.list();
tx.commit();


for (Iterator iter = allnewsletter.iterator(); iter.hasNext() {
customers.add((Newsletter) iter.next());
}



return (Newsletter[]) customers.toArray(new Newsletter[0]);

}

Thanks
Rizwan
http://www.rizwan.in



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject: count the number of rows without retrieving them
PostPosted: Wed Feb 14, 2007 1:57 pm 
Newbie

Joined: Wed Jun 21, 2006 2:25 pm
Posts: 15
from section 14.13. Tips & Tricks of the Hibernate reference manual

You can count the number of query results without actually returning them:
( (Integer) session.iterate("select count(*) from ....").next() ).intValue()

Hope this helps

anand raman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 10:25 pm 
Newbie

Joined: Wed Jun 21, 2006 2:25 pm
Posts: 15
actually I found out that the session.iterate is defined in org.hibernate.classic.Session and has been deprecated as well.


You should be able to use the following instead

select count(a.debitTransactions.amount) from AccountImpl as a where a.debitTransactions.status = 'NORMAL' and a.accountStatus = 'ACTIVE' group by a

Cheers
anand raman


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 1:39 am 
Newbie

Joined: Wed Feb 14, 2007 2:51 am
Posts: 2
thanks that worked :-)

_________________
Best Regards
Rizwan
http://www.rizwan.in


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.