This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes one DAO querying 2 tables?  (Spring security, user & auth) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "one DAO querying 2 tables?  (Spring security, user & auth)" Watch "one DAO querying 2 tables?  (Spring security, user & auth)" New topic
Author

one DAO querying 2 tables? (Spring security, user & auth)

Christopher Whu
Ranch Hand

Joined: Sep 03, 2008
Posts: 80
I have a user DAO for a project, i added spring security to it, i now have a user_role table.

From your professional experience should i create a separate DAO/DTO fro the user_role?

I am always curious to see how others do this.

I apologize in advance for my English...
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
In some situations, it is better to implement a single DAO for each data source. For example, if the application is using data-oriented web services then there would be a DAO for this data. And if the application also is using a relational database then there would be a second DAO for the database. In cases where there is more than one relational database, a DAO for each database works well.
Christopher Whu
Ranch Hand

Joined: Sep 03, 2008
Posts: 80
in the end i just ended up creating a separate DAO & DTO for both the role(authority) and user table. I was really asking a coding style question. I am always curious to see if i am doing my programming the HIP and current way... I want to be like one of the cool kids...
Ryan Waggoner
Ranch Hand

Joined: Jun 27, 2007
Posts: 75
Christopher,

I agree with the decision you ended up making (for what its worth).
With the functionality so finite and different, I would create 2 DAOs.

With that being said, there are times where I have created DAOs that query 2 or more tables, because I need a little bit of information from each to get all of the data I need.
In these cases, I thought it would be silly looking to have a method that is declaring and using 5 DAOs to get the data I needed.

Note: As you can tell I made my decision solely on looks.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

I routinely work with very complex interrelationships and it has led me to develop a 2-tier persistency access architecture. The "service" classes access working sets of related tables and tend to contain persistence-related business logic. The "DAO" classes access individual tables and do the low-level find and CRUD functions. The service classes do not contain entityManagers. Instead, they invoke the DAOs. Transactions are bounded at the service level.


Customer surveys are for companies who didn't pay proper attention to begin with.
Christopher Whu
Ranch Hand

Joined: Sep 03, 2008
Posts: 80
Thank you for all the incite... My code usually works but i always want to see what everyone else does...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: one DAO querying 2 tables? (Spring security, user & auth)
 
Similar Threads
design a flexible application security
Problem in Many to Many mapping -
Design help needed.(basic)
Web Application Architecture
Need help for Many to Many association