I have two classes:
Course {
...
private List<Student> students;
private String var1;
...
}
Student {
private Long id;
...
}
In my code, I was able to generate the following query dynamically and get results successfully:
SELECT c.var1 FROM Course c, IN (c.students) s WHERE s.id = :sid
Now I would like to do a update with the following dynamically generated query:
UPDATE c SET c.var1 = 'newvalue' FROM Course c, IN (c.students) s WHERE s.id = :sid
For this, I always got error:
org.springframework.dao.InvalidDataAccessApiUsageException: node to traverse cannot be null!; nested exception is java.lang.IllegalArgumentException: node to traverse cannot be null!
The reason I came up with the above UPDATE query is because I read this SO post:
How can I do an UPDATE statement with JOIN in SQL?
Here is my code:
Query query = em.createQuery("UPDATE c SET c.var1 = 'newvalue' FROM Course c, IN (c.students) s WHERE s.id = :sid");
query.setParameter("sid", 10);
query.executeUpdate();
Thanks for help!