aspose file tools
The moose likes Object Relational Mapping and the fly likes Relationship between tables in DAO pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Relationship between tables in DAO pattern" Watch "Relationship between tables in DAO pattern" New topic
Author

Relationship between tables in DAO pattern

Huy Hang
Greenhorn

Joined: Jul 22, 2005
Posts: 5
I use DAO pattern.
I wanna get data from 4 tables, which dto will I use ?
Create new dto content all attribute I need ?
and create new DAO interface, DAO implements class ?
Thanks for rely !
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8141
    
  52

If the 4 tables represent 4 INDEPENDENT entities, i believe you should create separate DTOs for each of them.
Ex:
Tables:
CONTINENT ( Name varchar , poupulation Integer);
COUNTRY (Name varchar, poulation Integer, Number literacyRate);
VILLAGE (Name varchar, population Integer, Number literacyRate);

You would have DTOs as follows:

class ContinentDTO {
String name;
int population;
//This would be a collection of Country DTO
Collection countries;


}

class CountryDTO {
String name;
int population;
double literacyRate;
//This would be a collection of Village DTO
Collection villages;

//this would refer to the continent DTO to which this country belongs
ContinentDTO continent;


}

class VillageDTO {
String name;
int population;
double literacyRate;

//this would refer to the country to which this village belongs
CountryDTO country;
}


[My Blog] [JavaRanch Journal]
Huy Hang
Greenhorn

Joined: Jul 22, 2005
Posts: 5
That is a good ideal but I wanna get data from 4 tables so that Object return contents attributes exist in 4 tables. Will i create new dto object
Example :
Have 4 tables : A, B, C, D with attribute A.a, B.b, C.c, D.d
"select A.a, B.b, C.c, D.d where ...."
which DAO object I can put in ?
Jack Wiesenthaler
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Originally posted by jaikiran pai:
If the 4 tables represent 4 INDEPENDENT entities, i believe you should


Who told you this? The purpose of a Transfer object is to transfer data between the data access layer and the client requesting the data. The Transfer Object has nothing to do with entities! A Transfer Object can simply be used to represent the data returned by the consolidation of many remote calls into a single call.

I think you should read the Design Pattern definition again ;-)
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8141
    
  52

Sorry, my thinking was wrong.
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 625

You should create 4 DAOs for for 4 tables and probably a single DTO with the help of Data Transfer Object Assembler.

-Jignesh
Huy Hang
Greenhorn

Joined: Jul 22, 2005
Posts: 5
I agree in DAO pattern 1 Table map to a DAO. But my query section get data from 4 tables. How can u do ?
Pj Murray
Ranch Hand

Joined: Sep 24, 2004
Posts: 194
Hello Huy,

You appear to be using FireStorm/DAO. You could look at the FAQ

http://www.codefutures.com/products/firestorm/faq/jdbc/complexqueries.html


FireStorm/DAO supports Table DAOs, View DAOs, Stored Procedure DAOs, and Custom SQL DAOs. Custom SQL DAOs can be used to expose pretty much any SQL statement as a DAO object (multi-table joins, bulk updates, etc.)


PJ Murray - Sites developed using CodeFutures technology:
lawinjuryaccidentsclaim
Siamak Saarmann
Ranch Hand

Joined: Aug 21, 2004
Posts: 77
PJ

FAQ does not say how we can relate result columns to getter/setter methods.

As an example if we have the first query:

SELECT a.*, b.* FROM a, b WHERE a.id = b.id AND b.install_date between ? and ?

How are we going to name setter/getter methods? (we may have fields with the same column name coming from different tables).

I am not able to find the answer for this.

Would you please forward me to a tutorial or a reference?

Siamak


PhD Candidate: Distributed and Parallel Systems, Simulation and Modeling
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Relationship between tables in DAO pattern
 
Similar Threads
OO Design
Diff b/w Dao's and valueobjectpattern?
How to implement DAO design pattern in Struts?
Session Bean + DAO
Designing DTO and ActionForm