-->
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.  [ 1 post ] 
Author Message
 Post subject: Result column aliases
PostPosted: Fri Nov 11, 2011 7:50 pm 
Newbie

Joined: Fri Nov 11, 2011 7:26 pm
Posts: 2
I have been using Hibernate 3.3 with success by mapping 1 (one) database table to 1 (one) entity class automatically by using HQL query. In my new project however, I am using a native SQL query that is fetching data from 4 different tables. (I will use stored procedures and functions in the future, that's why I need the native SQL query). I want to assign the returned values to 1 entity class. My understanding is that I need to use result column aliases (or placeholders).

On page 284 of the book "Hibernate in Action" there is an example of placeholders - the names enclosed in braces:

String sql = "select u.USER_ID as {uzer.id},"
+ " u.FIRSTNAME as {uzer.firstname},"
+ " u.LASTNAME as {uzer.lastname} from USERS u";

List results = session.createSQLQuery(sql, "uzer", User.class).list();

If my understanding is correct here, Hibernate returns the column USER_ID of the table USERS and assigns it to the field id of the User class via the alias/placeholder "uzer", the same way it assigns the column USERNAME to the field firstname of the same entity class, LASTNAME to lastname, etc. Well, this was Hibernate version 2, I think, and this method is deprecated in version 3. And I couldn't find a similar example in the 2nd version of this book (called "Java Persistence with Hibernate").

Can someone please tell me (preferably with example code) how to do the same thing in version 3.3, or do I need to go back to version 2 or use another ORM tool?

Any help is much appreciated.


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

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.