-->
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: Column Alias in hibernate native query
PostPosted: Wed Mar 02, 2011 3:27 pm 
Newbie

Joined: Fri Feb 25, 2011 2:34 am
Posts: 11
hi friends,
Can we use column alias in a hibernate native sql query, i found we cannt , if we do we have to use addScalar function and give the type of column we want to return, the problem with this is we have to change the code if we alter the structure of the table,


Also i found we cannt use a query like:

SELECT IF(true,'',textcolumn) from sometable

where textcolumn is a column of type text .(i am using mysql).

pl advice how can we do a if and either return a varchar and a text value.

pl advise ,
thanks
abhishek


Top
 Profile  
 
 Post subject: Re: Column Alias in hibernate native query
PostPosted: Wed Mar 02, 2011 5:16 pm 
Beginner
Beginner

Joined: Fri Apr 28, 2006 7:48 am
Posts: 20
Hi,

If this is what you are trying, then it worked for me . I am using oracle 10g but I dont think that should be a problem
List l = session.createSQLQuery("SELECT FIRSTNAME FNAME FROM EMPLOYEE WHERE EMP_ID=82").addScalar("FNAME", Hibernate.STRING).list() ;
List l1 = session.createSQLQuery("SELECT decode(LASTNAME,null,UPPER(FIRSTNAME),LOWER(FIRSTNAME)) NEW_FNAME FROM EMPLOYEE WHERE EMP_ID=82").addScalar("NEW_FNAME", Hibernate.STRING).list() ;;

If it is still not working, can you please pass on the exact code.


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.