Entity Bean Home Methods

Discussions

EJB programming & troubleshooting: Entity Bean Home Methods

  1. Entity Bean Home Methods (6 messages)

    What are the situations in which we prefer an entity bean <br>home method to business methods in remote interface ?

    Threaded Messages (6)

  2. Entity Bean Home Methods[ Go to top ]

    Hi!

    I think you shd read about Factory pattern (GoF).

    According to my understanding Home methods are like Factory methods while business methods are product methods.

    In other words... functionality which should work accross entities should be in home... while functionality which is for a specific entity shd be in EJB..Object.

    Hope it helps.
  3. Entity Bean Home Methods[ Go to top ]

    Thaks a lot ,Manish.
    I have gone through the GoF Factory Pattern.
    So it means when an operation needs to work with more than one instance
    to obtain the desired result can be a home method.
    Now could you please explain how will we implement it in CMP ..i mean
    how will the ejbHomeMethodName() and deployment descriptor for this will look like?
             Thanks in advance
                       bijukumar
  4. Entity Bean Home Methods[ Go to top ]

    Thanks a lot ,Manish.
    I have gone through the GoF Factory Pattern.
    So it means when an operation needs to work with more than one instance to obtain the desired result can be a home method. Now could you please explain how will we implement it in CMP ..i mean how will the ejbHomeMethodName() and deployment descriptor for this will look like?
             Thanks in advance
                       bijukumar
  5. Entity Bean Home Methods[ Go to top ]

    This is an example of ejb Home interface;

    AccountLocalHome.java :
    public String[] getAllAccountsForCustomer(String custRef); //Home interface.

    AccountBean.java //In bean provide implementation for home interface method.
    public String[] ejbHomeGetAllAccountsForCustomer(String custRef)
    throws FinderException
    {
    /* Step 1 : an ejbselect call to get all accounts for the customer - custRef. */
    /* Step 2 : create a string array of account names and return */
    }

    Deployment descriptor :
    Nothing specific is required. But You would give ejbselect ( step 1) query when you define Entity Account - something like this..

    <entity>
       <display-name>Account</display-name>
       <ejb-name>AccountBean</ejb-name>

               <query>
                    <query-method>
                        <method-name>ejbSelectByCustomerReference</method-name>
                        <method-params>
                            <method-param>java.lang.String</method-param>
                        </method-params>
                    </query-method>
                    <ejb-ql>SELECT DISTINCT OBJECT(acct) FROM AccountBean AS acct WHERE acct.custReferenceNumber = ?1</ejb-ql>
                </query>



    Hope this helps.
  6. Entity Bean Home Methods[ Go to top ]

    This is an example of ejb Home interface;

    AccountLocalHome.java :
    public String[] getAllAccountsForCustomer(String custRef); //Home interface.

    AccountBean.java //In bean provide implementation for home interface method.
    public String[] ejbHomeGetAllAccountsForCustomer(String custRef)
    throws FinderException
    {
    /* Step 1 : an ejbselect call to get all accounts for the customer - custRef. */
    /* Step 2 : create a string array of account names and return */
    }

    Deployment descriptor :
    Nothing specific is required. But You would give ejbselect ( step 1) query when you define Entity Account - something like this..

    <entity>
       <display-name>Account</display-name>
       <ejb-name>AccountBean</ejb-name>
       ....
       <query>
       <query-method>
       <method-name>ejbSelectByCustomerReference</method-name>
       <method-params>
           <method-param>java.lang.String</method-param>
           </method-params>
       </query-method>
       <ejb-ql>SELECT DISTINCT OBJECT(acct) FROM AccountBean AS acct WHERE acct.custReferenceNumber = ?1</ejb-ql>
       </query>
    </entity>
       ....
       ....

    Hope this helps.

    -arun
  7. Entity Bean Home Methods[ Go to top ]

    The best analogy for home methods that I have come up with is static methods in normal Java classes. Any time you have a method that is not associated with a particular business object, but rather with the "class" of the business object, would be a candidate for a home method.

    In practice, I don't use home methods much, however. Since they are a new and marginal part of the spec, they make me nervous. I put the type of operations that would go in a home method into independent Stateless Session Beans instead.