Wednesday, August 10, 2011

Hibernate Query vs SQL Query ( Inner Join )

Requirement :


Students table : student_id,student_name ( student_id primary key )


Courses table : course_id,course_name ( course_id primary key )


Student_Course table : student_id,course_id ( student_id,course_id foreign key references )


how to join these 3 tables ....


Case : 1 



select s.student_id,s.student_name,c.course_id,c.course_name from students s inner join student_course sc on s.student_id= sc.student_id inner join courses c on c.course_id=sc.course_id;

Case : 2 

select s.student_name,c.course_name from students s inner join student_course sc on s.student_id=sc.student_id inner join courses c on c.course_id=sc.course_id;


Hibernate Query :  ( from Student as s inner join s.courses )
Note : Student ( Pojo BeanClassName ) , courses : object of set interface in Student Pojo :


Happy Learing !! 

vaass

 









No comments:

Post a Comment