0

i've implemented a composite pattern/tree. That means i have a Parent and a Leaf Class, both descending from the Class Components. The parent class has an attribute that contains a List of Components. This is being saved properly in the Database using Hibernate. When i want to display this tree i get the root element from the database with

Parent root = (Parent) session.createQuery("FROM Parent WHERE id=1").uniqueResult();

and then iterate recursively over the ComponentsList Attribute of this Parent object.

Now we come to my problem: I want to limit the result from the database dynamically. For example the leafs have an integer attribute called "size", and i want to show only that leafs in the tree, that have a leaf.size greater than 100 (i get the value 100 from an html form).

How do I do this? What do i have to change at the code being shown above so that it works? I have something in mind like (its just pseudo code):

session.createQuery("FROM Parent WHERE id=1").limitGT(Leaf.class, "size", 100).uniqeResult();
Ragadabing
  • 472
  • 2
  • 7
  • 14
  • http://stackoverflow.com/questions/1239723/how-do-you-do-a-limit-query-in-hql – Zeus Dec 11 '13 at 20:34
  • The problem is not that i just want to get 10 results instead of all, (in fact i just get one single Parent object), the problem is that i want to limit the objects that are being fetched by hibernate with lazy loading automatically. So they are not being fetched directly by this line above, but the when i use the getter of the Parent Class for the List. – Ragadabing Dec 11 '13 at 20:38

0 Answers0