-->
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.  [ 3 posts ] 
Author Message
 Post subject: Building IQuery programmatically (ie, no prebuilt string)
PostPosted: Thu Feb 01, 2007 5:52 pm 
Beginner
Beginner

Joined: Thu Dec 21, 2006 11:38 am
Posts: 30
Looking at the object model, I'm not seeing how to build queries programmatically.

For instance, my UI's have "Filtering" options that tailor a string query for a GridView.

Is there a way to do this in a more granular way? Something like:

Code:
//retrieve
IQuery query = this.Session.CreateQuery("from Account");

if(this.txtName.Text != "")
    query.Add(String?)Criteria("Name", this.txtName.Text);

if(this.txtNumber.Text != "")
   query.Add(String?)Criteria("AccountNumber", this.txtNumber.Text);

if(this.chkIncludeClosed.Checked==false)
   query.Add(Boolean?)Criteria("IsClosed",false)



Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 12:18 am 
Beginner
Beginner

Joined: Mon Jan 08, 2007 11:59 pm
Posts: 31
I think Criteria API was created for this purpose. Can't you use Criteria instead of IQuery?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 6:04 am 
Newbie

Joined: Tue Dec 12, 2006 3:19 am
Posts: 17
Location: Spain
Hi
As samueljob said, you could use the Criteria API, so you could code sentences like:

Code:
Criteria criterio = session.createCriteria(Account.class);

//filter 1
if(this.txtName.Text != "")
criterio.add(Restrictions.like("name",(String)this.txtName.Text) ));

//filter 2
if(this.chkIncludeClosed.Checked==false)
criterio.add(Restrictions.eq("name",(Boolean) this.chkIncludeClosed) ));



As you can see, you would use like, eq, in and so on options.

For more information, have a look to:
http://www.hibernate.org/hib_docs/v3/re ... g-criteria


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