hey there,
I have two classes with a one-to-many relationship. For ilustration:

public class Customer
    Business business;
    Date created;

public class Business


Now, when I do the following:

new StringBuilder().append("SELECT business FROM ").append(Customer.class.getName())

it works perfectly fine. However, when I include filtering based on created field of Customer, the query fails. Although, (SELECT * FROM Customer) with the where clause included works well. Can someone please guide me on what to look for or what is it that I am doing wrong

Thanks in advance.

5 Years
Discussion Span
Last Post by bibiki

Bibiki can you explain what error you get??Are you using filter correctly??Until you show the filter that you are using i can't help.
For reference for filter in HQL read http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/filters.html or http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/filters.html

For example you can also refer http://www.mkyong.com/hibernate/hibernate-data-filter-example-xml-and-annotation/

If still problem is not solved,provide error logs.


hey IIM, thank you very much for your reply.
This is how I am filtering:

String builder hql = new StringBuilder().append("SELECT business FROM ").append(Customer.class.getName())
.append(" WHERE created >=:created");
Query tempQuery = getSessionFactory().getCurrentSession().createQuery(hql.toString()).setParameter("created", new Date(new Date().getTime() - lastDays*1000*3600*24l));
List<Business> businesses = (List<Business>)tempQuery.list();

The error I get is "invalid identifier CREATED". So, I am not using any filter named methods. What do you think?


instead of setParamter() try query below.I have also changed a bit in query.If its working then good,otherwise i will try this in my system and help you to solve this.

 String builder hql = new StringBuilder().append("SELECT c.business FROM Customer c")
.append(" WHERE c.created >=:created");
 Query tempQuery = getSessionFactory().getCurrentSession().createQuery(hql.toString()).setDate("created", new Date(new Date().getTime() - lastDays*1000*3600*24l));

hey IIM, thank you very much. That worked perfectly fine. I have been trying to do this two days now but I couldn't figure out why it wouldn't work.

thanks again. I'm marking this thread as solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.