pankaj
pankaj

Reputation: 553

Get data from two tables and insert in one table through HQL

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

Answers (1)

Munees Majid
Munees Majid

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

Related Questions