-->
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: HQL-undefined alias
PostPosted: Fri Jun 25, 2004 8:49 pm 
Newbie

Joined: Mon Jun 21, 2004 3:43 pm
Posts: 19
Code:
      Session s = sessions.openSession();
      Transaction ts = null;
      //User u1= new User();
      List result = null;
      ts = s.beginTransaction();
          Query q = s.createQuery(
              "select User.uno, User.uname " +
              "from User "
          );
          q.setMaxResults(3);
          result = q.list();
          for (int i=0; i< result.size(); i++) {
  Long id = (Long) result.get(i);
  System.out.println(id.longValue());
          }
          ts.commit();

      s.close();


Really don't understand how HQL works, any help? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 11:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I think you need to spend some more time reading the manual.
Anyway, change you query to :

Code:
"select u.uno, u.uname from User u "

which will result in an List of Arrays with two entries.
Your debugger can show you the details if your unsure,

Or to collect the complete User class try:

Code:
"from User"


which collects a List of all User objects.
Please note User should have the full path to the class.

Code:
"from my.project.User"


HQL has its basic structured based on SQL (as much of it can be passed directly to the SQL engine). Just need to get use to the object aspects of it.


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.