• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Joining Tables in DAO

 
Cj Recto
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hellow guys, I'm currently on learning using Dao pattern in my project. So as what I know, one Table is equivalent to one DAO, am I right? just like StudentDao, SubjectDao. Each dao performs crud operations in their associated tables. But my question is , how am I going to create a DAO for joined tables? lets say I have a query to join student and subject table, then how do I create a DAO for that? Should I place it to the StudentDao? or to SubjectDao? or there's a good practice in that kind of situation?

TIA!
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you call StudentDAO and SubjectDAO seems to be Transfer Object and can be as many as you need. They are all created and managed by a layer, the DAO.
So it's not right that one table is one DAO. One DAO manages access to one or more tables, even joined, using one or more transfer objects.

Look at this blueprint, it could help you.

http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html


 
Cj Recto
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean it's wrong to assume that a one DAO access only one table? I thought that one DAO access only one table as what I've seen on many examples. So if I have Student table, I would create a StudentDao which will perform all crud operations in student table. Hmm... I'm a bit lost here!

Can you site some examples.?

Thanks for your link, I'm currently reading it.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to follow the code listed in the blueprints, starting from example 9.1, apply it to your model and once you have done something post your doubts
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicola Garofalo wrote:What you call StudentDAO and SubjectDAO seems to be Transfer Object and can be as many as you need. They are all created and managed by a layer, the DAO.
So it's not right that one table is one DAO. One DAO manages access to one or more tables, even joined, using one or more transfer objects.

Look at this blueprint, it could help you.

http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html




You seem to be being a bit harsh, but the link is good.To answer your specific question the studentDAO will return a list of courses the student is taking, it is 1 DAO per object not 1 per table
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have been warned about cross posting before, i just found exactly the same text in stack overflow, Please don't waste peoples time.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy Gibbons wrote:
You seem to be being a bit harsh...


Sorry for that, i didn't mean to be
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicola Garofalo wrote:
Wendy Gibbons wrote:
You seem to be being a bit harsh...


Sorry for that, i didn't mean to be

I have been on another forum for work today, and the staff on there are just some of the rudest I have ever seen, so I may be a little sensitive today
 
Cj Recto
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for taking time to answering my questions.

Sorry to offend you guys for cross posting. It's just that I'm on a project that needs to meet deadline. We have no senior programmer to ask and guide us regarding this matter. Especially when it comes to application design patterns. Most of our projects were developed without any pattern, "Just do it the way you want it". So I'm eager to learn from those expert people.

Again I apologize!
 
Cj Recto
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another question regarding DAO and DTO, please correct me guys if my understanding is right. So we have tables which has a corresponding POJO classes, my questions is does those POJO classes equivaltent to DTO?

I understand that DAO will perform CRUD operations on the database. Please correct me if I am getting it right.

Thanks!
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A DTO is a dumb class it stands for Data Transfer Object, it doesn't do any real processing, it's only job is to move data around the system in a single object.

so a POJO (plain old java object) may be a DTO or it may not.
 
Cj Recto
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
uhmm I see... Thanks for helping :-)
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic