81.OK, so EJB doesn’t support user-created threads. So how do I perform tasks asynchronously?If your EJB does not need to know about the results of the aynch calls, then you can use JMS to send an asynch. message to another part of the system. Another alternative is to place the multithreaded code inside a CORBA or RMI server and call this from your EJB. Always keep site of the big picture, RMI and CORBA are part of J2EE and can be used as part of a ‘J2EE’ solution. There are some things that these technologies can do that EJB at this present time cannot. 82.What is an EJB Context?EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJB Context called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details 83.Can I deploy a new EJB without restarting my server? (I’m using Weblogic.)Sure. WebLogic Server4.5 includes “hot deploy” feature that allow you to deploy, redeploy or undeploy EJBs while the Server is running, from the Weblogic Console. Deployment of EJBs made through the console are however lost when you restart the WebLogic Server. 84.How to setup access control in an EJB such that different application clients have different rights to invoke different methods in one EJB?
2 .. p.put(Context.SECURITY_PRINCIPAL,"user"); 3 p.put(Context.SECURITY_CREDENTIALS,"password"); ...
2 {if(ejbContext.isCallerInRole("manager"))returnbalance; } You could also enforce security to your EJB server. Using Weblogic, you could add the following to your weblogic.properties file: 1 ... weblogic.password.user=password ... where “user” is the username you grant access for and “password” (after ‘=’) is the password for this username 85.How is persistence implemented in enterprise beans?Persistence in EJB is taken care of in two ways, depending on how you implement your beans: container managed persistence (CMP) or bean managed persistence (BMP). For CMP, the EJB container which your beans run under takes care of the persistence of the fields you have declared to be persisted with the database – this declaration is in the deployment descriptor. So, anytime you modify a field in a CMP bean, as soon as the method you have executed is finished, the new data is persisted to the database by the container. For BMP, the EJB bean developer is responsible for defining the persistence routines in the proper places in the bean, for instance, the ejbCreate(), ejbStore(), ejbRemove() methods would be developed by the bean developer to make calls to the database. The container is responsible, in BMP, to call the appropriate method on the bean. So, if the bean is being looked up, when the create() method is called on the Home interface, then the container is responsible for calling the ejbCreate() method in the bean, which should have functionality inside for going to the database and looking up the data. 86.Can the primary key in the entity bean be a Java primitive type such as int?The primary key can’t be a primitive type–use the primitive wrapper classes, instead. For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive). 87.How do I map a Date/Time field to an Oracle database with CMP?[Question continues: (I have written a wrapper class with the help of java.util.GregorianCalendar but it doesn’t store time in Oracle database, whereas it stores Date without any problem.)] 88.What is the difference between a Server, a Container, and a Connector? To keep things (very) simple:
An EJB server is an application, usually a product such as BEA WebLogic, that provides (or should provide) for concurrent client connections and manages system resources such as threads, processes, memory, database connections, network connections, etc. 89.What is “clustering” in EJB?Clustering refers to the ability of multiple load-balanced web servers to share session and entity data. It is a major feature of web application servers. Standardized support for clustering was one of the primary motivations behind the EJB spec. 90.What is “hot deployment” in WebLogic?“Hot Deployment” in weblogic is the act of deploying, re-depolying, and un-deploying EJBs while the server is still running (you don’t have to shutdown the server to deploy an EJB). 91. Can I specify specific WHERE clauses for a find method in a CMP Entity Bean? The EJB query language is totally vendor specific in EJB1.1. It is being standardized in 1.2.
Yes, you can specify the where clause for a find method. This is the example for EJB’s deployed on weblogic: 92.When using a stateful session bean with an idle timeout set, how can the bean receive notification from the container that it is being removed due to timeout?(Through some tests, it looks like none of the standard EJB callback methods are called when a stateful session bean is removed due to idle-timeout.)]
93.I have created a remote reference to an EJB in FirstServlet. Can I put the reference in a servlet session and use that in SecondServlet?Yes. 94.What is the difference between a Component Transaction Monitor (CTM) and an Application Server?A Component Transaction Monitor (CTM) is an application server that uses a server-side component model. Since a CTM is a Transaction Processing monitor (TP), it is expected to provide services for managing transactions, security, and concurrency. In addition, CTMs also facilitate distributed object architectures and provide facilities for object persistence. In short, a CTM is a specific type of application server 95.How can I call one EJB from inside of another EJB?Just do it! 96.When using Primary Keys, why do I have to implement the hashCode() and equals() method in my bean? Implementing the hashCode() and equals() functions ensure that the primary key object works properly when used with hash tables. Hash tables are the preferred way EJB servers use to store and quickly retrieve instantiated entity beans. 97.Can I deploy two beans in a single jar file? If so, how?Yes, multiple EJBs can be deployed in a single jar file. The deployment is somewhat different between EJB 1.0 and EJB 1.1.
In EJB 1.1 and in the draft EJB 2.0 specification, instead of a manifest and serialized deployment descriptors there is a single shared XML deployment descriptor named META-INF/ejb-jar.xml. Within ejb-jar.xml there must be either a 98.Why use EJB when we can do the same thing with servlets?Actually, servlets/JSPs and EJB are complementary, not competing technologies: Servlets provide support for writing web based applications whereas EJBs provide support for writing transactional objects. In larger web systems that require scalability, servlet and JSP or XML/XSL technologies provide support for the front end (UI, client) code, where EJB provides support for the back end (database connection pooling, declaritive transactions, declaritive security, standardized parameterization…) The most significant difference between a web application using only servlets and one using servlets with EJBs is that the EJB model mandates a separation between display and business logic. This is generally considered a Good Thing in non-trivial applications because it allows for internal reuse, allows flexibility by providing a separation of concerns, gives a logical separation for work, and allows the business logic to be tested separately from the UI (among others). Some of the hings that servlets and JSPs can do that EJBs cannot are:
99.What restrictions are imposed on an EJB? That is, what can’t an EJB do?From the spec:
100.Why do we have a remove method in both EJBHome and EJBObject?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 statefull) to inform the container of your loss of interest in this bean. |