ejbSelect() Method !

Discussions

EJB design: ejbSelect() Method !

  1. ejbSelect() Method ! (5 messages)

    Hi
    Consider that i have one entity bean with relation to 3 or 4 other entity beans, I want to read some information from this group of entites, I want to know is it better to write a EJBSelect method in one them and use that method for doing this or it is better to do it from my client (for example servlet) and read that information with a FOR and iterate over collection of them.

    tell me which one is more efficient [Time and Performance]
    Thanks
    --Amir Hossein

    Threaded Messages (5)

  2. ejbSelect() Method ![ Go to top ]

    The best solution is to write a session bean with the logic to invoke all the entities and assemble your data. The session bean can store the data in lightweight value objects. The client can then call the session bean. This is generally referred to as the Session Facade pattern.

    http://java.sun.com/blueprints/patterns/SessionFacade.html

    The reasoning behind this pattern is:

    1) If the client invokes the Entities directly, it is horribly ineffecient (you can end up with dozens of extraneous database calls).

    2) It is often a bad idea for one Entity EJB to invoke a different Entity except for very controlled ways (like Container Managed Relationships).
  3. When ?[ Go to top ]

    Thanks for your answer , but actually my question is about when i should use ejbSelect() and ejbHome methods, consider that i'm talking about cmp and container managed relationship,
    please compare this in 2 conditions :
    1-do my reads in a session bean from 3 CMPs with relationship
    2-write a ejbselect method in one the CMPs and then call this method from sessoin bean

    Thanks
    I'm looking forward for my answer ;)
    thanks
  4. When ?[ Go to top ]

    An ejbSelect() method is useful when you want to retrieve exactly one fiel from an Entity bean. If you only need a single field from a given Entity, the ejbSelect() can be more efficient. If you need multiple fiels, I would use the entities normal getter methods instead.

    As for ejbHome() methods, they are more or less functionally equivalent to methods in your stateless session beans. Personally, I am a bit suspicious of them, because they are obscure and new in the spec, and therefore less likely to be as well tests as session beans. That is a personal bias, though.
  5. Thanks[ Go to top ]

    Thanks paul for your aswers,
  6. ejbSelect() Method ![ Go to top ]

    Hi,

    EjbHome method are used for

    1. These methods pertain to the overall table or atleast more than one entity and thus cannot be put into Remote Interface . E.g Total number of employees in the company. To achieve the same thing without home method we would have been forced to put a method FindAllEmployees() and then determine the size of the collection returned.This is inefficient as it is a memory hogger.
    2.Because they do not pertain to any specific entity for there execution a bean lying in pool is used.

    EjbSelect() method is used for

    It’s a finder method in CMP Bean that is transparent to client and is used solely by the bean code. Its useful because its return type need not only be collection of Primary Keys. It can be any collection of any CMP field as well. E.g If in execution of some method we need total salary of all the employees then we can use a select method that can return us collection of Salary field whereas using Finder method would be cumbersome and a memory hogger.

    Regards,
    Rinku