Patrick Arnesen wrote:
I'm trying to create a simple project/task management application. A project contains tasks, which can be either assigned to a user (ProjectMember), or stored in a tray (TaskTray), it it's not assigned to any user.
I have a syntax question for the hibernate query language:
Here's what the classes would look like
class Task
{
long id;
TaskOwner assignedTo;
}
abstract class TaskOwner
{
long id;
}
class ProjectMember extends TaskOwner
{
User user;
}
class TaskTray extends TaskOwner
{
String trayName;
}
class User
{
long id;
String firstName;
String lastName;
}
So a task is assigned to a taskOwner, which is either a ProjectMember, or a TaskTray.
Now, I want to create a hibernate query to retrieve all the tasks for a particular user. The closest I've been able to come up with would be the following, but it's invalid syntax:
Query query = getSession().createQuery(
"from Task as task " +
"inner join ProjectMember as member " +
"where task.assignedTo.id = member.id " +
"and member.user = :user ");
Does anyone know how to express this query properly? I can't do "where task.assignedTo.user = :user", because I'd have to cast assignedTo to ProjectMember first, and I don't know how to do that.
Thanks.... Patrick Arnesen
when you do joins in HQL, you're specifying Class attributes so it would be
.... inner join task.assignedTo as assignedTo
I might be able to give you more info if you post your mapping files.