Hi All,
I am using Criteria API to fetch a domain object based on some conditions.
But the SQL query fired by Hibernate contains all the columns from all the tables it is doing the join on.
Sql Query being fired:
Code:
SELECT this_.teacher_id AS person1_1_5_,
this_1_.first_name AS first2_1_5_,
this_1_.middle_name AS middle3_1_5_,
this_1_.last_name AS last4_1_5_,
this_1_.birth_date AS birth5_1_5_,
this_1_.sex AS sex1_5_,
this_1_.email AS email1_5_,
this_1_.phone_num AS phone8_1_5_,
this_.dept_id AS dept2_2_5_,
this_.salary AS salary2_5_,
this_.designation AS designat4_2_5_,
this_.is_hod AS is5_2_5_,
alias5x5_.dept_id AS dept1_6_0_,
alias5x5_.dept_name AS dept2_6_0_,
alias5x5_.dept_code AS dept3_6_0_,
courses8_.teacher_id AS teacher1_,
alias1x1_.course_id AS course2_,
alias1x1_.course_id AS course1_7_1_,
alias1x1_.course_cd AS course2_7_1_,
alias1x1_.course_desc AS course3_7_1_,
alias2x2_.enrollment_id AS enrollment1_8_2_,
alias2x2_.audit_number AS audit2_8_2_,
alias2x2_.course_id AS course3_8_2_,
alias2x2_.student_id AS student4_8_2_,
alias3x3_.student_id AS person1_1_3_,
alias3x3_1_.first_name AS first2_1_3_,
alias3x3_1_.middle_name AS middle3_1_3_,
alias3x3_1_.last_name AS last4_1_3_,
alias3x3_1_.birth_date AS birth5_1_3_,
alias3x3_1_.sex AS sex1_3_,
alias3x3_1_.email AS email1_3_,
alias3x3_1_.phone_num AS phone8_1_3_,
alias3x3_.mentor_id AS mentor2_4_3_,
alias3x3_.room_id AS room3_4_3_,
alias3x3_.roll_num AS roll4_4_3_,
alias4x4_.enrollment_history_id AS enrollment1_9_4_,
alias4x4_.audit_number AS audit2_9_4_,
alias4x4_.enrl_date AS enrl3_9_4_,
alias4x4_.grade AS grade9_4_,
alias4x4_.enrollment_id AS enrollment5_9_4_
FROM sf_teacher this_
INNER JOIN sf_person this_1_ ON this_.teacher_id = this_1_.person_id
INNER JOIN sf_department alias5x5_ ON this_.dept_id = alias5x5_.dept_id
INNER JOIN sf_teacher_course_mapping courses8_ ON this_.teacher_id = courses8_.teacher_id
INNER JOIN sf_course alias1x1_ ON courses8_.course_id = alias1x1_.course_id
INNER JOIN sf_enrollment alias2x2_ ON alias1x1_.course_id = alias2x2_.course_id
INNER JOIN sf_student alias3x3_ ON alias2x2_.student_id = alias3x3_.student_id LEFT
OUTER JOIN sf_person alias3x3_1_ ON alias3x3_.student_id = alias3x3_1_.person_id
INNER JOIN sf_enrollment_history alias4x4_ ON alias2x2_.enrollment_id = alias4x4_.enrollment_id
WHERE alias3x3_1_.first_name = 'Test3'
AND alias4x4_.grade = 'A+'
AND alias4x4_.audit_number = alias2x2_.audit_number
But, I am only interested in data from table sf_teacher.
This might help to reduce the network traffic from the Database to the Application Server, as the data transferred will be significantly reduced.
Is there any way specify that only columns from the specified domain is fetched ?
--Kiran