hellow guys, currently I'm creating web application based on hibernate and spring. I just have some question regarding the design patterns of using DAO layer.
So lets say I have two tables, Student table and Subject table. Then I have 2 DAO to perform crud operations with the table.
The DAO layer :
for student;
Code:
public class StudentDaoImpl implements StudentDao {
@Autowired
private SessionFactory sessionFactory;
public Student getStudeByPk(string studentid){
// load instance of student
return sessionFactory.getCurrentSession().load(Student.class, studentid);
}
public void saveStudent(Student student){
sessionFactor.getCurrentSession.save(student);
}
}
for subject:
Code:
public class SubjectDaoImpl implements SubjectDao {
@Autowired
private SessionFactory sessionFactory;
public Subject getSubjectByPk(string subjectId){
// load instance of subject
return sessionFactory.getCurrentSession().load(Subject.class, subjectId);
}
public void saveSubject(Subject subject){
sessionFactor.getCurrentSession.save(subject);
}
}
So as you can see, both dao performs direct access to single table.
My question is what if I want to join two tables? what approach do I need to do in order to do that?
Any help would be appreciated!