I'm really stuck on something that seems like it should be easy. I have a Spring MVC webapp using Hibernate version 3.6.6. I have two objects - "ProjectUser" and "Project" - with a many-to-many relationship described in the database by the tables "users, "projects", and "projects_users." I have a portion of my app where I want to update the users in a project without updating any other fields in the "projects" table (it's a big table with lots of fields), so the easiest thing seemed to be to just write a separate method in my DAO and call the HQL directly. Here's the relevant portion of the "projects" class:
Code:
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "projects_users", joinColumns = @JoinColumn(name = "project_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
private Set<ProjectUser> projectUsers ;
Everything works just fine on a select and also works if I pass along a full Project object and just call "session.saveOrUpdate(project)." However, my HQL to just update the users clearly has problems. Here's what I'm executing now:
Code:
Query query = getSession().createQuery("update Project set projectUsers = :projectUsers where id = :projectID ");
query.setParameter("projectUsers", project.getProjectUsers());
query.setParameter("projectID", project.getId());
int result = query.executeUpdate();
When I run this, I get a SQLGrammarException that reads "no value specified for parameter 2." It looks like I have a syntax error when I'm passing through the Set of ProjectUsers (if I run this same code on another field that does not involve a join it all works fine), but I can't figure out what to change to make this work. Any help would be appreciated.
Thanks,
Alex