Reputation: 553
I have two entity classes Student.java
and Course.java
and they have many to many
relationship between them I want to add one entry into their @JoinTable
through hql like this :
insert into student_course(student_id,course_id) values('" + courseId + "','" + studentId + "')".
I want to use hql instead of sql. Any ideas?
Upvotes: 1
Views: 864
Reputation: 767
You can try a solution like this
insert into student_course(student_id,course_id)
select c.student_id,c.course_id from Student s join s.Course c
Upvotes: 2