Home Java Technology EJB EJB Sample Interview Questions - 4

Login Form




EJB Sample Interview Questions - 4 Print E-mail

1. What level of Load Balancing is possible with EJBs?
Answer: The workload management service provides load balancing for the following types of enterprise beans:

2. Is is possible for an EJB client to marshal an object of class java.lang.Class to an EJB?
Answer: Technically yes, spec.compliant NO! - The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the Java language.

3. What is the default transaction attribute for an EJB?
Answer: There is no default transaction attribute for an EJB.Section 11.5 of EJB v1.1 spec says that the deployer must specify a value for the transaction attribute for those methods having container managed transaction.In WebLogic, the default transaction attribute for EJB is SUPPORTS.

4. Why do we have a remove method in both EJBHome and EJBObject?
Answer: With the EJBHome version of the remove, you are able to delete an entity bean without first instantiating it (you can provide a PrimaryKey object as a parameter to the remove method).The home version only works for entity beans.On the other hand, the Remote interface version works on an entity bean that you have already instantiated.In addition, the remote version also works on session beans (stateless and stateful) to inform the container of your loss of interest in this bean.

5. Are we allowed to change the transaction isolation property in middle of a transaction?
Answer: No.You cannot change the transaction isolation level in the middle of transaction.

6. Is it possible to share an HttpSession between a JSP and EJB? What happens when any one changes a value in the HttpSession from inside an EJB?
Answer: You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as "passed-by-value", that means that it's read-only in the EJB.If anything is altered from inside the EJB, it won't be reflected back to the HttpSession of the Servlet Container.The "pass-by-reference" can be used between EJBs Remote Interfaces, as they are remote references.While it IS possible to pass an HttpSession as a parameter to an EJB object, it is considered to be "bad practice (1)" in terms of object oriented design.This is because you are creating an unnecessary coupling between back-end objects (ejbs) and front-end objects (HttpSession).Create a higher-level of abstraction for your ejb's api.Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end.Consider the case where your ejb needs to support a non-http-based client.This higher level of abstraction will be flexible enough to support it.(1) Core J2EE design patterns (2001)

7. What is EJBDoclet?
Answer: EJBDoclet is an open source JavaDoc doclet that generates a lot of the EJB related source files from custom JavaDoc comments tags embedded in the EJB source file.

8. Is there any way to force an Entity Bean to store itself to the db? I don't wanna wait for the container to update the db, I want to do it NOW! Is it possible?
Answer: Specify the transaction attribute of the bean as RequiresNew.Then as per section 11.6.2.4 of the EJB v 1.1 spec EJB container automatically starts a new transaction before the method call.The container also performs the commit protocol before the method result is sent to the client.

9. Is there a guarantee of uniqueness for entity beans?
Answer: There is no such guarantee.The server (or servers) can instantiate as many instances of the same underlying Entity Bean (with the same PK) as it wants.However, each instance is guaranteed to have up-to-date data values, and be transactionally consistent, so uniqueness is not required.This allows the server to scale the system to support multiple threads, multiple concurrent requests, and multiple hosts.

10. What's new in the EJB 2.0 specification?
Answer: Following are the main features supported in EJB 2.0: Integration of EJB with JMS, Message Driven Beans, Implement additional Business methods in Home interface which are not specific for bean instance, EJB QL.