• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

When to use session beans...

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic