-->
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: Dynamic Query
PostPosted: Thu Nov 22, 2012 11:58 am 
Newbie

Joined: Thu Nov 22, 2012 11:50 am
Posts: 3
Hi Guys.

I need to create a dynamic query for search...

Kind of:

Code:
if (field != null){
  query.append("AND field = "+field);
}


Of course, that is a lazy example...

But I want to make it DYNAMIC AND GENERIC.
For that I´m thinking in creating a helper, like:

Code:
public class WhatEver{
    private String fieldName;
    private Object fieldObject;
    private Class<?> filterclass;
    private String operation; //refector for a ENUM latter on, like "equals", ">", "<", "between"
    private String matchMode; //if necessary
    private boolean isList; //if I want to filter in a list, I have to create a JOIN here... but don´t know if I can do this
}


And create the query using criteria...
In a method, where I receive a list of "WhatEver", Sorting Field, Sorting ASC/DESC...
And the Root entityClass ...


If I can make this... I don´t need to create one query PER entity, that I´ll have in my CRUD with dynamic filters.

Anybody have this implemmented or can help me with it?


Top
 Profile  
 
 Post subject: Re: Dynamic Query
PostPosted: Fri Nov 23, 2012 1:19 pm 
Newbie

Joined: Fri Nov 23, 2012 12:03 pm
Posts: 4
Hi
As per my understanding what you are trying to do is to create a Helper class which can be used as a generic Query class which gives you dynamic queries
when you pass different parameters.

This is very well possible.
Anyways you have a class holder inside this helper class where you can pass your className and you can set different constraints and sorting values to the different holder you have in the class.

Then pass this class as follows : getDefaultDao().findUsing(className).
I hope this is what you are looking for. Let me know if you need any more clarification.


Top
 Profile  
 
 Post subject: Re: Dynamic Query
PostPosted: Fri Nov 23, 2012 1:37 pm 
Newbie

Joined: Thu Nov 22, 2012 11:50 am
Posts: 3
Hello

thanks for the reply...
Actually I´m creating that HelperClass, but I´m having some problem in createAlias :(

Can you check this post out:
https://forum.hibernate.org/viewtopic.php?f=1&t=1024830
Thanks!


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.