-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate + Spring problem on DAO layer design pattern
PostPosted: Wed May 30, 2012 10:05 pm 
Newbie

Joined: Mon Mar 05, 2012 1:49 am
Posts: 7
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.