-->
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.  [ 5 posts ] 
Author Message
 Post subject: String function Left(field, length) in HQL?
PostPosted: Mon Oct 15, 2007 3:55 pm 
Newbie

Joined: Sat Aug 04, 2007 8:12 am
Posts: 4
Hi,

I'm just wondering if I can do the string function Left(Field, length) using HQL?

For example, the select statement in SQL
SELECT Left(Lastname,1), Count(*)
FROM MyTable
GROUP BY Left(Lastname,1)
ORDER BY Left(Lastname,1)

I tried to do it but received the following error message:
undefined alias or unknown mapping: Left [select new countobj(Left(obj.LastName, 1), count(obj.ID)) from MyObj obj group by Left(obj.LastName, 1) order by Left(obj.LastName, 1)]

Will I able to accomplish this using HQL?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 15, 2007 4:13 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
I'm not aware of any, but you can use IQuery/session.CreateSQLQuery() to use a raw SQL query to populate a mapped entity. I've never used it for substrings, but have used it for aggregate functions. Check chapter 13 of the NHibernate docs and see if that does it for you.

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 15, 2007 10:08 pm 
Newbie

Joined: Sat Aug 04, 2007 8:12 am
Posts: 4
Hi!

Thanks for your response. I've got it working with SQLQuery

Thanks again!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 3:41 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
You should also be able to implement this using query substitution.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 1:22 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
True that, to check out that approach start with:
See Nhibernate docs chapter 3 Section 3.5.4

Whichever work best for your team I say.

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


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