wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Best Practices in Ejb Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Best Practices in Ejb Doubt" Watch "Best Practices in Ejb Doubt" New topic
Author

Best Practices in Ejb Doubt

Prashant Vasudeo
Ranch Hand

Joined: Mar 25, 2003
Posts: 38
hi,
I am reading "mastering ejb" by ad roman.
while raeding the "ejb best parctices and performance optimizations" chapter..
i am getting the follwing line...can anybody explain it in details probably with example..
thanks in advance..
"you should wraps entity beans with session beans.The session bean perform bulk create,read,update,delete operations on behalf of remote clients.The session beans also serve as transactional facade,enforcing that transaction occurs on the server,rather than involving remote client.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Originally posted by Prashant G:

"you should wraps entity beans with session beans.The session bean perform bulk create,read,update,delete operations on behalf of remote clients.The session beans also serve as transactional facade,enforcing that transaction occurs on the server,rather than involving remote client.

Exactly. This is the well-known session facade design pattern. The idea is that you can have remote clients (running anywhere in the network) invoking methods to perform a single unit of work. The remote client will probably need to do more than one network call (executing many methods) to perform a single unit of work. and this consumes resources (network calls, etc).
So putting a session between in the middle improves your design, not only in terms of network consumption, but as well as decoupling your presentation layer with your business logic. Clients should never access entity beans directly, instead session beans access them using local interfaces (that do not require network calls).
Also imagine how hard it would be to manage transactions using client-entity comunication.
With a session bean as a facade, you can "tell" your container (via deployment descriptor) to handle transactions.
Imagine also if your client is using a standalone application and he asks you to migrate the code to a web application. Having all your business logic in the session bean reduces the amount of work you have to do. You are decoupling your application.
what would happen if you need to change the structure of your table in the dabase? i.e., modifying a field ? You probably do not need to change anything on your clients because clients are not communicating directly with the entity bean.. they know nothing about your database structure, all your logic is placed in the bean.
hope it helps


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Prashant .. forgot let u know...
EJB design patterns by floyd marinescu (FREE pdf available as well). Excellent book... it'll wipe all your doubts...
Prashant Vasudeo
Ranch Hand

Joined: Mar 25, 2003
Posts: 38
thanks a lot Andres...
again one doubt.."The session beans also serve as transactional facade,enforcing that transaction occurs on the server,rather than involving remote client."
please tell me know what i understand is right for the above statement.
It means that rather than "client will initiate" a transaction involving entity bean in the client code, provide the session bean method interface which will wrap the entity bean and also start the transaction by using deployment description on the server.
This means rather than client initiates the transction, the transaction work will be done by the container which will be on the server.

------------
prashant
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
right
Prashant Vasudeo
Ranch Hand

Joined: Mar 25, 2003
Posts: 38
thanks andres
-------------
prashant
 
Don't get me started about those stupid light bulbs.
 
subject: Best Practices in Ejb Doubt
 
Similar Threads
unable to deploy stateless session bean using weblogic 7
weblogic-ejb-jar.xml prblems ....
Ant Build in Websphere Application Server5
Unit Tests and Session Beans
EJB3 unit tesing for session beans