Hi This is from Whizlabs again. When would you use the DAO pattern in regards to a Stateful Session Bean? Ans is : You wdn't use DAO with SFSB Because it is expensive. My question is But if you were to do Database read/write , wouldn't it be appropriate to use DAO? Thanks Debanjana
I don't entirely agree with whiz labs. One of the purposes of DAO is to uncouple the biz tier from a DB implementation. SFSB to DAO is local references and I don't see a huge performance hit. What does the rest of the peanut gallery think?
Thomas Hofmann
Ranch Hand
Joined: Nov 23, 2002
Posts: 72
posted
0
Data access objects (DAO) encapsulate database access code (JDBC, SQLJ, ...). So DAO is appropriate also for SFSB. The usage of DAO doesn't depend on the EJB type u use.
Bhagawanlu Durvasula
Ranch Hand
Joined: May 15, 2002
Posts: 41
posted
0
Hi Debanjana, I agree with Rufus, and if you really were to do some DB operations in SFSB, you could use DAO alternatively, but it would not really a performance killer. Regards Durvasula
SCJP2, SCWCD, SCBCD, SCDJWS, SCEA
Chris Mathews
Ranch Hand
Joined: Jul 18, 2001
Posts: 2712
posted
0
This question has come up before, however I am too lazy to search for that thread... Possibly, the intention of the Whiz Labs' answer was that one should not be doing database access from within a Stateful Session Bean. In general, that is good advice but I would never make such a blanket statement. In most cases SFSB is not a good choice for database heavy activities, however there are situations where it is. One thing that makes SFSBs powerful, and therefore a viable choice at times, is their ability to interact with transactions via the SessionSynchronization interface. To get back to the question at hand, if I were to access a database from a SFSB then I would certainly use DAO to encapsulate that activity. I completely agree with Rufus's assessment of the purpose of DAO.
Debanjana Dasgupta
Ranch Hand
Joined: Aug 11, 2000
Posts: 101
posted
0
Thanks Guys for your replies. I thought so too. Debanjana
Sanjay Raghavan
Ranch Hand
Joined: May 14, 2002
Posts: 148
posted
0
As Chris says, its not appropriate to say that you would never use SFSB with DAOs. But as Chris also points out, the author meant that from a best practices point of view, rather than a feasibility point. Although SUN would vouch for SFSB, I have not seen too many EJB implementations where SFSB are even used. They are expensive to maintain. Also (according to the best practices) you would use DAOs to retrieve data (and possibly update data that is non-concurrent). Could you use a SFSB to manage the retrieval/update, yes you could. But if your app already has a SFSB for managing state, you will probably leverage it from your Session Managers (Stateless beans that interact with DAOs). Hope this helps.
Sanjay Raghavan<br />SCJP2, SCEA-J2EE<br />Moderator - <a href="http://groups.yahoo.com/group/scea_prep" target="_blank" rel="nofollow">SCEA PREP</a><br />Co-Author - <a href="http://www.whizlabs.com/scea/scea.html" target="_blank" rel="nofollow">SCEA@Whiz</a><br /><i>Where did you sip your Java Today?</i>