Static methods in EJB 1.1 Entity Beans ??


EJB design: Static methods in EJB 1.1 Entity Beans ??

  1. Static methods in EJB 1.1 Entity Beans ?? (3 messages)


    Hope somebody has tried this out or knows the answer ...

    Is it possible to have static methods in EJB 1.1 entity beans?

    The rationale for having a static method is as follows:

    Lets say that a 'Customer Entity Bean' C and an 'Order Entity Bean' O exist in a system.

    If I want to find out all the Orders that a particular customer has, I can call a finder method on the O bean. But, lets say that I don't want to instantiate all the beans that will contain the underlying order data, but only want a list of PO #s. It would NOT make sense to instantiate all the order beans just to get PO #s. This would happen if I was to call a regular finder method.

    The first thought that I had was to put this type of bulk data lookup into a stateless session bean and use that method to get the PO #s.

    But, I was wondering if it would be possible to place the same lookup as a static method in the entity bean itself.


  2. Static methods in EJB 1.1 Entity Beans ??[ Go to top ]

    Well, I just checked the 1.1 spec and took a look at section 9.2.6 which says

    "Business Methods

    The entity bean classmay define zero or more business methods whose signatures must follow these rules:




    *** The method must not be declared as final or static.



    *** This makes sens since a business method that operates on bean instance data should not be static.

    But for a method that does not really operate on the bean internal data, does this really make sense??

  3. Static methods in EJB 1.1 Entity Beans ??[ Go to top ]

    You can have static methods/variables in your Entity (or Session, for that matter) Beans. Whether it's a good decision to do so depends on what you're trying to do.
    Generally, I only use protected/private static methods/attribs in beans. If they are public, they probably belong in a separate class/bean.

    For what you describe, I would either a) do it in a session bean as you describe, or b) put a method on your customer entity bean "getPOs()".
  4. Hi,

    From my understanding , when you call the finder method on the O bean, it Will not instantiate all the beans containing the order data. In fact the finder method will return only the primary keys to the container and only EJBObjects will be created for each order data. You can get the PO #s from this info.

    Hope this helps.


    (I am slightly out of touch with the EJB's but I think what I have mentioned above is right)