aspose file tools*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Using Java EE entities over DAO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Using Java EE entities over DAO" Watch "Using Java EE entities over DAO" New topic
Author

Using Java EE entities over DAO

Joe O'Toole
Ranch Hand

Joined: Mar 02, 2009
Posts: 51
Hi

Could somebody please explain to me in what circumstances it makes sense to use Java EE Entities over DAO.

Conversely - when does it make sense to use DAO over Java EE Entities

Thanks!
Joe
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
Well it depends on the complexity of your persistence layer. If it is very simple you could do without DAO.
But most of the time you will find entities and DAO are used in combination even when the persistenc layer is very simple.
It just keeps your business logic separated from your persistence logic.
In that case a DAO manages the persistence of a specific entity. It is sometimes called EAO for Entity Access Object.


SCJP 5 , SCWCD 5, SCEA 5
Joe O'Toole
Ranch Hand

Joined: Mar 02, 2009
Posts: 51
Thanks for the response ntumba.

Actuall, from re-reading my question I don't think I was entirely clear. Really, what I mean to say in what circumstances would you use JPA/EJB3 over DAO

Thanks
Joe
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
oh I see so your question is ORM vs pure JDBC.
In that case you would use an ORM you when have a complex OO business to persist in DB and you want to favor ease of development.
The pure JDBC approach is more used for relatively simple applications or when you want to tune your data access for better performance.
And again you can mix both approaches in the same application to cater for edge cases.
I hope that's more in line with your question now.
Joe O'Toole
Ranch Hand

Joined: Mar 02, 2009
Posts: 51
Hi Ntumba

Thanks for the response.

Sorry really what I was getting at is why would you go the DAO route to persist your data as opposed to JPA.

From reading more I think I would go the DAO route if the persist store is a file, or the data is being retrieved from stored proc's or finally you want to decouple persist info from the business object.

Think you would use JPA for Rapid development and Java domain layer is a good fit to DB tables

Thoughts?

Thanks
Joe

Lakshman Arun
Greenhorn

Joined: Sep 24, 2008
Posts: 19
DAO is a layer between the business logic and persistent logic. The layer can use different frameworks for doing the persistence of objects, could be JPA/JDO and vendor specific implementations like hibernate etc.

Irrespective of the complexity/size of the application, its always better to have well defined contracts(interfaces) between the layers.
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
DAO and JPA are not mutually exclusive concepts, you can have DAOs with JPA code.
So if your question is when using JPA is appropriate or not, the answer will be that whenever you have objects that need to be stored in a relational database you can use JPA.
Any other storage like flat files, LDAP for example you would have DAO with the appropriate logic for the specific storage.
JPA caters only for object to relational DB storage.

Regarding last response, Im sorry but the complexity/size of an app is a factor affecting the decision of using an ORM or not.
The cost of adding an ORM is not null, in some cases a simple design a more suited than a rigorous more complex one -> KISS
Joe O'Toole
Ranch Hand

Joined: Mar 02, 2009
Posts: 51
Thanks Ntumba
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi
Could someone tell me what the book discusses EAO pattern?
And if someone already used EAO in your assignament?


Fernando Franzini - Java Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Java EE entities over DAO