This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes When to use session beans... 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 "When to use session beans..." Watch "When to use session beans..." New topic
Author

When to use session beans...

Damien Joldersma
Greenhorn

Joined: Mar 24, 2005
Posts: 4
Am I correct to be using a session bean to gather a collection of child EJB objects?

What I'm trying to avoid is this case where I created a simple findAll() EJB query that returns a collection of child entities. The problem is that when I get my collection and begin to walk through it, it is doing a subsequent database connection for *each* element as it renders it on screen. So, instead of doing 1 database fetch for the object and all it's children, I'm doing N trips to the database where N is the number of child EJB entity references.

Can I use a session bean to get them all at once and return them as a unit? Or am I simply using the pattern wrong and there is a better/more correct way to work with an entity and it's children?
Anil Sadi
Greenhorn

Joined: Jan 09, 2001
Posts: 23
Hi Damien,

1. You can use the session facade design pattern in this context. Facade is a simple stateless session bean.
2. Keep the session bean method which collects the EJB Objects in transaction context. It saves the database calls for each method call on entity bean.
3. Use local interfaces for entity beans to save from remote calls.
4. Another good approach is use Home business methods to get the collection of Value Objects instead of EJBObject stubs from entity bean.

Hope it helps!!!

Anil S
 
jQuery in Action, 2nd edition
 
subject: When to use session beans...