• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Design: should I add a 'DAO' layer between my Session bean and my Entities?

 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm new to EJB3, and would like to ask a design question:

Is it customary to add a 'Data Access' layer between the Session beans and the Entities?
Or would your Session bean simply access the Entity API directly?

For example, say I have a 'Bank' session bean, and Account entities.

Then Bank can directly access the Entity API:


But I'm considering an alternative of writing a Data Access layer, something like the following.
It seems more work, but the session bean becomes more readable (especially if it has some additional complex logic and not just simple 'find'), and it can hide some sql implementation choices (e.g. if we find some way to optimize the query, or move to native sql, etc):


Of course this is a simplified example... in real life, the code may be more complex (especially the Session logic), and a query may be re-used from several methods.

If anyone can share their views, and/or refer me to EBJ design tutorials, it will be appreciated.
Thanks
[ September 24, 2007: Message edited by: Sol Ma-Orn ]
 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sol,

I would use a DAOFactory in your Session Bean. See the links I gave in this thread why DAO? from JavaRanch's ORM forum for more info.

Regards,
Darya
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the excellent reply and the link.

Can I just ask: how do you make the DAO available to the Session bean?
I'm considering 3 alternatives (see below).
Which seems most reasonable, in your experience ? Or do you have a different, better approach?
Thanks again.

Options I was considering:





[ September 26, 2007: Message edited by: Sol Mayer-Orn ]
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about a factory which returns the DAO instance. The factory could be configured to return the correct instance depending on a configuration which is set before the EJB container starts up.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Roger Chung-Wee, for this reply.
The factory approach sounds good - neat and flexible.

But in that case, could I just shift my question a little: how do you make the *Factory* available to the Session bean ? Is your factory just a static method (or static singleton) ? Or is your factory a Local session bean ? etc.

Thanks again
 
reply
    Bookmark Topic Watch Topic
  • New Topic