-->
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.  [ 7 posts ] 
Author Message
 Post subject: HQL Query with Nhibernate
PostPosted: Sun Oct 24, 2010 11:29 am 
Newbie

Joined: Sun Sep 26, 2010 2:09 am
Posts: 11
i want to pick a specific column from the DataBase table "department" , the column name is
'DeptName' working with HQL in Nhibernate


public IList<CMM_Dept_Info> GetAllDeptNames()
{
ICriteria criteria = Session.CreateCriteria<CMM_Dept_Info>("SELECT Dept_Name FROM CMM_Dept_Info");

return criteria.List<CMM_Dept_Info>();
}



this returns the Primary key column while i need the DeptNAme column that is ,the names


Please help


Top
 Profile  
 
 Post subject: Re: HQL Query with Nhibernate
PostPosted: Mon Oct 25, 2010 8:22 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Criterias do not work with SQL. Do you mean session.CreateQuery ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: HQL Query with Nhibernate
PostPosted: Mon Oct 25, 2010 9:44 am 
Newbie

Joined: Sun Sep 26, 2010 2:09 am
Posts: 11
ok

how can i do this ??
i mean i want to pick a field "DeptName" from the table "DEpt_Info"

dept_name is not a primary key field


Top
 Profile  
 
 Post subject: Re: HQL Query with Nhibernate
PostPosted: Mon Oct 25, 2010 10:03 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
public IList<CMM_Dept_Info> GetAllDeptNames()
{
Session.CreateQuery("SELECT di.Dept_Name FROM CMM_Dept_Info di");
return criteria.List<string>();
}

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: HQL Query with Nhibernate
PostPosted: Mon Oct 25, 2010 10:20 am 
Newbie

Joined: Sun Sep 26, 2010 2:09 am
Posts: 11
Thank GOD
done man :D

public IList<CMM_Dept_Info> GetAllDeptNames()
{
ICriteria criteria = Session.CreateCriteria<CMM_Dept_Info>();
Session.CreateQuery("SELECT di.DeptName FROM CMM_Dept_Info di");
return criteria.List<CMM_Dept_Info>();
}


Thanks to u too


Top
 Profile  
 
 Post subject: Re: HQL Query with Nhibernate
PostPosted: Mon Oct 25, 2010 10:32 am 
Newbie

Joined: Sun Sep 26, 2010 2:09 am
Posts: 11
Can u please tell me the difference between IQuery and HQL ?


Top
 Profile  
 
 Post subject: Re: HQL Query with Nhibernate
PostPosted: Mon Oct 25, 2010 11:14 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
There's non IQuery = HQL. ICriteria is different.

Query/HBM
http://nhforge.org/doc/nh/en/index.html#queryhql

Criteria
http://nhforge.org/doc/nh/en/index.html#querycriteria

_________________
--Wolfgang


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