aspose file tools*
The moose likes JDBC and the fly likes Joining Tables in DAO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Joining Tables in DAO" Watch "Joining Tables in DAO" New topic
Author

Joining Tables in DAO

Cj Recto
Greenhorn

Joined: Mar 02, 2012
Posts: 26
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

Joined: Apr 10, 2010
Posts: 308
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



Bye,
Nicola
Cj Recto
Greenhorn

Joined: Mar 02, 2012
Posts: 26
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

Joined: Apr 10, 2010
Posts: 308
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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Apr 10, 2010
Posts: 308
Wendy Gibbons wrote:
You seem to be being a bit harsh...


Sorry for that, i didn't mean to be
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Mar 02, 2012
Posts: 26
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

Joined: Mar 02, 2012
Posts: 26
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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Mar 02, 2012
Posts: 26
uhmm I see... Thanks for helping :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Joining Tables in DAO