URGENT !!! - ejbLoad and ejbStore query ...

Discussions

EJB design: URGENT !!! - ejbLoad and ejbStore query ...

  1. URGENT !!! - ejbLoad and ejbStore query ... (13 messages)

    Hi !
    The system is "Online purchasing system", where in the supplier and the user negotiates on the quantity that is needed and qty could be supplied, online. The system architecture is a session bean acts as a client for the BMP entity bean. I have a search screen which has three select fields listing "item_planners", "item_code" and "item_supplier" respectively. In the session bean business methods getPlanner(), getItemCode(), getSupplier(), I lookup entity bean and call the entity bean business methods getPlannerList(), getItemCodeList(), getSupplierList(). In the entity bean business method, I interact with the database and return the hashtable which contains the item number. Since Iam new to EJB, I've implemented this type of logic. Is is a right EJB approach. If that is the case what is the use of "ejbLoad()" and "ejbStore()" methods. When should I use these two methods. In my system I got to update the database after the search result is complete. That is, the search result displays the details of the item (around 300 items), wherein the user or the supplier can edit the quantity that is needed or the qty that could be supplied respectively, which has to be updated in the database. Please give me the solution to proceed.

    Thanx
    AJP
  2. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Look at the top right hand corner of the home page. There is a free download available. Read it :)Ok to be concise, these methods are automatically called by the server and you dont have to use them. At most you can use the isModified method to set a dirty flag compelling a call on the ejbStore().Also the methods you defined in the Entity and the Session beans should be flipped over, because it is the Session bean which would intiates a DB request.
  3. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Hi !
    Thanx for ur response. What does it mean by "flipped over" and my confusion is whether to insert any code in ejbload() or ejbstore method. Because the idea what I had was to have empty implementation of these methods and have separate business methods to do the database retrieval and updation.

    Thanx again
    AJP
  4. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    u see entity bean is persistent so it should have getters and setters. The session bean will intiate the DB connexion and get the rows for you. So basically the calls in entity beans should be in the session bean and vice versa. Also just dont bother at this stage about the load and store...
  5. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    ok i forgot the last part. It seems you are using CMP. So dont bother about ejbLoad and ejbStore. Just add the necessary fields in the deployment descriptor.

    Pavan
  6. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Hi !
    I use BMP entity bean. So I got to implement ejbLoad() and ejbStore() method. And the problem for me is to how to code according to the specification. I'll repeat my problem :

    The system architecture is a session bean acts as a client for the BMP entity bean. I have a search screen which has three select fields listing all "item_planners", "item_code" and "item_supplier" respectively. In the session bean business methods getPlanner(), getItemCode(), getSupplier(), I lookup entity bean and call the entity bean business methods getPlannerList(), getItemCodeList(), getSupplierList(). In the entity bean business method, I interact with the database and return the hashtable which contains the item number. Since Iam new to EJB, I've implemented this type of logic. Is is a right EJB approach. If that is the case what is the use of "ejbLoad()" and "ejbStore()" methods. When should I use these two methods. In my system I got to update the database after the search result is complete. That is, the search result displays the details of the item (around 300 items), wherein the user or the supplier can edit the quantity that is needed or the qty that could be supplied respectively, which has to be updated in the database. Sorry to bother u so much.

    Thanx
    AJP
  7. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    It is not compulsory to implement ejbload and ejbstore methods. If you are not reliant on these methods simply you can ommit (no implementation). In BMP, these methods will be called by container when the transaction(ejbload) strats and when the transactions(ejbstore) completes. Ofcourse there are some other instances at that time also container calls these methods like ejbpassivate etc. You can use these methods to format the data before storing in database.


    Gamini
  8. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Hi Gamini !
    That should be fine, but can I include database code in my business methods directly or it should be included only in container methods like ejbLoad and ejbStore. Will it not be EJB specification violation or something like not making use of EJB container, if I interact with the database directly in the business method and have empty implementation of ejbLoad and ejbStore. That is my basic doubt.

    Thanx
    AJP
  9. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Hi AJP,
    I just read thru your design & I think you are missing the point behind entity beans. Entity Beans are meant to provide an "object" view of your data which may be stored in an RDBMS. Each entity bean essentially represents a single logical row on the database. (A logical row may span multiple tables).

    Now, I see that you want to get lists of planners,suppliers etc based on a search screen. For this, it is better to simply use a session bean to make a JDBC call to the tables & return a list of Java objects which represent your business object. For instance, you could return a Collection of Planner objects when you call getPlannerList() method on your session bean. Thus all your XXXList() methods would be on your session bean. The session bean would make the database call & return the list of Planners or Suppliers.

    Now, instead of constructing Java objects (after making a query from the session bean), if you create entity beans to represent all the planners & suppliers (i.e an entity bean to represent each logical database row), I think you'll wind up with a huge number of entity beans which will unnecessarily hog the container's resources. If you look at the Patterns section on this site, you'll find some interesting patterns. I'd recommend the Value/Details Object Pattern discussion. It would answer some of your questions.

    So, to summarize - to return lists of "business objects" do not use entity beans. Use a session bean which would directly retrieve the lists via JDBC calls. Create ordinary Java objects to represent each object in your Collection & return it to the client to generate the web page.

    Hope this helps.
    --Das
  10. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Hi Das !
    It was really an excellent explanation. I really appreciate that. But still I have some doubts.
    I can retrieve the planner list, supplier list etc from JDBC calls in session bean business method itself. When the user selects any or all select fields and submits, then I should list the result which is multiple records which I'll get from a finder method in entity bean in the form of Enumeration.
    I guess, after finder method is invoked, the container automatically calls ejbLoad method. Since the finder method returns enumeration in my case, can ejbLoad method load multiple records. How is the process between finder method that has enumeration(multiple records) and ejbLoad. Is the ejbLoad method called for each PK (object) of enumeration.
    I appreciate ur work.

    Thanx
    AJP
  11. Hi guys,

    Hey....U guys started discussing with EntityBean and ended up with a design of Session Bean.
    First we'll analyse the Requirement.

    It seems as soon as the User logs in you have to populate all the 1)item_planner 2)item_code 3)item_supplier.

    After this user will select a item from each of this and will do a querry on it to get some result...right!!


    Here we go:

    For getting all the item related details from the database and to populate in browser..

    Use a stateless Session Bean with database querries, which will send a hashtable with data of item 1,2,3.
    bring this hashtable to EJBClient and display it in the Select field.


    For displaying the data related to a specific item_planner,item_code,item_supplier.....

    use a Entity Bean which will contain set and get methods.Either u can go for CMP or BMP.if it's CMP don't worry about ejbLoad and ejbStore which will be always called everytime while storing and retriving data. This u can overcome setting the flag to isModified method.
    If it's a BMP, pass the data from the client thro' finder methods (again depends on based on which item u r going to retrive the data). Again wrap this Entity with a session Bean, so that no need to call the get and set methods everytime u need a data related to set and get methods.Bring the data from Entity to session and pass it to client.

    Sounds convinicing!!!!

    regards
    Moorthi
  12. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Hi AJP,
    Okay, so once you get the lists from the session bean, your next task is to handle the searches. I assume your user could search on planner, supplier etc.

    First let me answer your doubt about finder methods. A finder method is a method on the bean's home interface. When you call the finder method, the container pulls out a free bean (from the free instance pool) and calls the ejbFindXXX() method on it. For instance, if you are calling the findPlannerByPrimaryKey(PlannerPK primaryKey) method the container pulls out a free bean and calls the ejbFindPlannerByPrimaryKey() method on it - this would return a PlannerPK. Before it is returned to the client, the container converts this PK object to an equivalent remote interface. So you can think of this as a new Planner bean being created to represent the bean whose PK you passed in. Any future calls you make on this bean's remote methods will be executed just as any other entity bean method.

    Now, in your case, you are planning to get an Enumeration of objects in return. It is not clear from your mail what exact objects you are returning (in fact, you can only return PK or remote interface of Planner bean), but let me assume that say you have a findPlannersByLocation(Location l) method which returns all planners in a geographical location denoted by "l". Now, this method would return an Enumeration of PlannerPKs representing all the planners in this location. The container creates a remote interface to represent each of these planners and each of these remote interfaces represent an individual Planner bean. So if your find method returns 100 planners, the container will have 100 remote references that you may decide to call methods on.

    As I said in my previous mail, this is again very resource intensive. Hence, I'd caution you from using finder methods to return Enumerations especially if the returned objects are large in number.

    I have found that most of such queries can easily be handled by a simple stateless session bean. For instance, your session bean can have a method called getPlannersForLocation(Location l) (where Location is Serializable, of course!). This can return a Collection of Planner objects (ordinary Java objects - hence lightweight) which may contain all the necessary attributes to be displayed for the user. No unnecessary entity beans hanging around to be passivated by the container!

    So, my advice is to use stateless session beans as much as possible.
    Hope this helps,
    --Das
  13. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Hi !
    Thanx again for ur explanation. I proceeded with the details I got and succeeded in returning the enumeration too. Here when I try to print the pk values (ie the 'item number' in my case) by using enumeration.hasMoreElements() and enumeration.nextElement(), I get something like this :

    EJBObject: '-405849934', home: 'Part', ctx: '-406636366', pk: '09370076'
    <BR>EJBObject: '-406898510', home: 'Part', ctx: '-407684942', pk: '16045980'
    <BR>EJBObject: '-407947086', home: 'Part', ctx: '-408733518', pk: '16235670'
    <BR>EJBObject: '-408995662', home: 'Part', ctx: '-409782094', pk: 'HA12187FP-EL'.

    In the above list the value which I require is pnly the 'pk'. So for each pk (which is 'item no'), I want to load the complete info (ie about 80 instance variables of the bean). How to do this. Actually I created a serializable helper class which has the constructor with 80 parameters for setting the instance variables. How to proceed from here. It should really be a great help if I get the solution asap. I get wonderful replies from u guys. Hope to get in this regard too.

    Thanx
    AJP
  14. URGENT !!! - ejbLoad and ejbStore query ...[ Go to top ]

    Hi !

    Some more doubts.

    I use stateless session bean as a client for the BMP entity bean. I use a business method in session bean which looks up entity bean bean and applies finder method to get the enumeration of remote interface. This enumeration is passed from entity bean to session bean and finally to the JSP client. In JSP client, the nextElement() method of enumeration, returns the remote interface of entity bean, so I have to use the entity bean directly. But the architecture of the system is JSP client talking to session bean which inturn talks to entity bean and finally to database. The retrieval is vice-versa.

    1. How should I get each element of enumeration without specifying entity bean directly from JSP client.

    2. Should I include any entry in deployment descriptor about the helper class the I use for getters and setters. And how to use the helper class for setting from client.

    Thanx

    Arun