-->
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.  [ 3 posts ] 
Author Message
 Post subject: session object does not have iterate or find methods
PostPosted: Tue Apr 04, 2006 4:32 pm 
Newbie

Joined: Tue Apr 04, 2006 4:09 pm
Posts: 2
Hibernate version: 3.1.3

Hello,

I'm reading through the documentation and in Chapter 14 Tips and Tricks I see:
You can count the number of query results without actually returning them:
( (Integer) session.iterate("select count(*) from ....").next() ).intValue()

When I try this:

Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
((Integer)session.iterate("select count(*) from Users where username = '" + username + "'").next() ).intValue();

It says: The method iterate(String) is undefined for the type Session.

My HibernateUtil class is a copy/paste from the one from Chapter 1, 1.2.5. Startup and helpers.

I also noticed that it is missing the 'find' method which is used in other examples.

Now;

1. I'm guessing that this is because I'm using org.apache.commons.dbcp.BasicDataSourceFactory as a factory. However I was not able to find a quick alternative to test this or documentation to verify it. Could one of you do this (confirm/deny I mean)?

2. There is another HibernateUtil class in the tomcat quickstart guide http://sun.calstatela.edu/~cysun/docume ... start.html but the session returned by that one doesn't have those methods either (duh!). So point 1 is probably valid.

- Could someone please either confirm or deny 1.
- Is the hibernate util class in the example good enough to use for a project or are there documented alternatives? If so, could someone point me to the resource where I can learn about this?
- Is there another factory I can just use as a replacement for BDSF without having to change anything else?

Thank you and good night.


Top
 Profile  
 
 Post subject: Tips and Tricks from FAQ is different.
PostPosted: Wed Apr 05, 2006 10:37 am 
Newbie

Joined: Tue Apr 04, 2006 4:09 pm
Posts: 2
Don't like to reply on myself but maybe this can help some other soul:

In the FAQ there is the following Tip:

How can I count the number of query results without actually returning them?

Integer count = (Integer) session.createQuery("select count(*) from ....").uniqueResult();

This is different from the Tip in the reference documentation. It would be nice to know which is preferred and what the difference is.

Also this not answers the question why my Session does not have the iterate and find methods.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 11:44 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
find and iterate were in the Hibernate 2 session but were removed from Hibernate 3 session. If needed, Hibernate 3 has the "classic" session that still contains find and iterate although they are deprecated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.