Archive for August, 2011

HQL DataSource – sometimes the simple answer

Posted by Jason Huber on August 23, 2011
Developer / No Comments

I recently had a situation where I wanted to show a “more tab” with a datagrid that would show data that had a secondary relationship to the entity on which it was placed.

The idea is on the User details I wanted to show the tasks assigned to that user through the project. In this scenario the project is assigned to the user. The task user is not the correct user.

So the relationship looks like this:

Users -> Projects -> tasks

Users has a .projects, but I cannot get the tasks to show using a traditional datagrid so I used a very simple HQL Query.

Add the HQL Data source to the page and the query can be as simple as (from) “Projects p inner join Tasks t”

The relationship is already defined, so we do not need to SQL “on p.projectid = t.projectid”

Now we can set our columns to whatever we want to show in the grid, add the grid and we are on our way.

Simple.