How can i design a EJB application using session Beana?


EJB design: How can i design a EJB application using session Beana?

  1. Hello, I am designing a Find application using EJB. Here a user is prompted a search page, where he can enter the search criteria's. Then on click of submit, the query is formed at the server side depending on what criteria's were selected. Then a jdbc query is performed and the results are returned back to the user. Here no session is maintained for the users. Can anyone suggest me how to design this application using EJB. Should i use entity beans for this or session beans will suffice? Should the jdbc query be performed in the bean itself or should it be outside in a helper class? Please kindlu suggest me the design for this application...
  2. Here are the approaches that I would ponder:

    Use the DAO (Data Access Object) pattern, to encapsulate the query and get the data. No need for EJBs at all. Use value objects to pass data to client. If you don't need to persits data then entity beans are way overkill.

    Do everything that the DAO pattern does but from within a stateless session bean. You benefit from container poolin, so this approach scales better than 1. above. Statefull session beans are also overkill since you are not persisting data or maintaining state.

    Hope it helps!
  3. Even I recommend the approaches suggested by Bido.

    1) If there are no EJBs in your application so far, then you don't need to add EJBs for this feature alone. You could do the search with some helper classes doing the search with JDBC.

    2) However if there are strong reasons for you to use EJB then the best solution here would be to use a stateless session bean. And I think it is a good practice to always keep the data access logic outside the session bean in the form of DAO or a helper class.

    3) If the data that you are trying to search was stored in the database using some EntityBeans, then providing various finder methods in the Entity Bean to get your search results would be the best way to approach the problem. However if your search is trying to retrieve data from various database tables then step2 is more appropriate
  4. Hi,
    I have deployed a session bean in Weblogic server. I was able to call that deployed bean from a standalone client. It's working.
    Now I am tring to call the same from the jsp/servlet. I have written the same code in the jsp and accessing the bean. But it is giving exceptions that the remote interface, home interface etc.. classes cannot be found. Basically there might be a classpath problem.(I have not added anything specific for this in web.xml and weblogic.xml.)
    What should i do for this? Should i add the deployed jar file to the weblogic server classpath in the starting script or should i add anything in web.xml.
    Please help me...

  5. You need to declare an ejb-ref tag in your web.xml. Below is an example. I suggest getting a hold of some Weblogic examples and mimicking them. Things can go wrong in too many places...



    <description>Define reference for a stateless session bean
  6. My copy/paste skills betrayed me... The above example is crippled. In any case, I hope it gives you and idea of what's involved.
  7. Thank you very much for yopur valuable advice.
    I have one more doubt. My input page will have a number of fields as search criterias. They are first name, lastname, userid, phone, street, etc...
    So the user may enter any of the criteria's and do a search. Can you please suggest how can i form the query dynamically based on the search criteria provided. Should i form the query at the client side ot should it be done at the server side?
    Once again thanks for your help..
  8. Toplink[ Go to top ]

      Take a look at products like Toplink which will take care of creating the dynamic queries and executing the queries for you.