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.  [ 2 posts ] 
Author Message
 Post subject: named parameters not working
PostPosted: Tue Jun 15, 2004 9:52 pm 
Newbie

Joined: Tue Jun 15, 2004 9:44 pm
Posts: 2
This works fine:

Code:
_RootDAO.initialize();
         Session session = _RootDAO.createSession();
         Transaction tx = session.beginTransaction();

         Query query = session.createQuery("from Cat cat");

         for (Iterator it = query.iterate(); it.hasNext();) {
            Cat cat = (Cat) it.next();
            out.println("Female Cat: " + cat.getName());
         }
         tx.commit();
         session.close();


When I used named parameters the query returns 0 records even though I know it should retun 1 record.

Code:
_RootDAO.initialize();
      Session session = _RootDAO.createSession();
      Transaction tx= session.beginTransaction();
      
            Query query = session.createQuery("from Cat cat where cat.name = :name");
            query.setString("name", "Prince");
            
            for (Iterator it = query.iterate(); it.hasNext();) {
                Cat cat = (Cat) it.next();
                out.println("Female Cat: " + cat.getName() );
            }
            tx.commit();
            session.close();


Also, the console is telling me the session is never closing, but only with the second example with named parameters


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 6:31 pm 
Newbie

Joined: Tue Jun 15, 2004 9:44 pm
Posts: 2
oops... my mistake. Didn't realize HQL was case sensitive with object names. Guess I'm still thinking in SQL terms.


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