I have three entities with relation UserDetails hasmany FiledTask and Task hasMany FiledTask. All I want is list of FiledTask of particular User
For UserDetails:
@OneToMany(mappedBy="user",cascade=CascadeType.ALL)
Collection<FiledTask> filedTasks = new ArrayList<FiledTask>();
And for Tasks I have
@OneToMany(mappedBy="task")
Collection<FiledTask> filedTasks = new ArrayList<FiledTask>();
And FiledTask looks like
@ManyToOne
@JoinColumn(nullable = false, name = "taskId")
private Tasks task;
@ManyToOne
@JoinColumn(nullable = false, name = "userId")
private UserDetails user;
I have tried
query = session.createQuery("from Tasks as tasks inner join tasks.filedTasks as files with files.user = :user");
query.setParameter("user", user); //user is UserDetails instance
But I am getting error clause can only reference columns in the driving table, means FiledTask can’t userId for comparision?
with clause can only reference columns in the driving table [from com.akhi.app.cdm.Tasks as tasks inner join tasks.filedTasks as files with files.user = :user]
If you want the FiledTasks of a given user, then the easiest thing to do is
Using HQL, it would be
If what you want is in fact the tasks of a given user, then the query would simply be
Note that the entity
Tasksshouldbe namedTask. An instance represents a single task, and not multiple ones.