Hi Derek,

Derek Broughton wrote:
Your Employee and Project classes define the employee-project relationship
as OneToMany in both directions.  I suppose that can work as you've done
it, but if you just define the relationship as ManyToMany you don't even
need to explicitly define the EmployeesProject class, it will be done
automagically.  Note that you only specify the "mapped by" in one direction
(it probably makes some difference in efficiency which side of the
relationship you use, but no difference in your programming).  I have to
admit, I don't know whether you could use the HQL above if the join class
is implicit - you might need "select employees from Project where
projectId=?".

@Entity
public class Employee extends BaseObject {
    private Long employeeId;
    private String employeeName;
    private List<Project> projects;
...
    @ManyToMany(mappedBy = "projects")
    public List<Project> getProjects() {
        return projects;
    }
You're absolutely right of course, I'd completely forgotten about the @ManyToMany annotation. I believe that a very slight tweak to your suggested HQL: "select employees from Project where Project.employeeId=?" should work if the Entities have an @ManyToMany annotation.

Cheers,

Rob Hills
Waikiki, Western Australia

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to