The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

41.What is a transaction?

A transaction is a single unit of work items which follows the ACID properties. ACID stands for Atomic, Consistent,Isolated and Durable.

42.What ACID stands for?

ACID stands for Atomic, Consistent,Isolated and Durable.
Explain ACID in context of transaction management.

  • Atomic - If any of work item fails, the complete unit is considered failed. Success meant all items executes successfully.
  • Consistent - A transaction must keep the system in consistent state.
  • Isolated - Each transaction executes independent of any other transaction.
  • Durable - Transaction should survive system failure if it has been executed or committed.

43.What is Container Managed Transactions?

In this type, container manages the transaction states.

44.What is Bean Managed Transactions?

In this type, developer manages the life cycle of transaction states.

45.Which are the attributes of Container Managed Transactions?

EJB 3.0 has specified following attributes of transactions which EJB containers implement:

  • REQUIRED - Indicates that business method has to be executed within transaction otherwise a new transaction will be started for that method.
  • REQUIRES_NEW - Indicates that a new transaction is to be started for the business method.
  • SUPPORTS - Indicates that business method will execute as part of transaction.
  • NOT_SUPPORTED - Indicates that business method should not be executed as part of transaction.
  • MANDATORY - Indicates that business method will execute as part of transaction otherwise exception will be thrown.
  • NEVER - Indicates if business method executes as part of transaction then an exception will be thrown.

46.Which are the attributes of Bean Managed Transactions?

In Bean Managed Transactions, Transactions can be managed by handling exceptions at application level. Following are the key points to be considered:

  • Start - When to start a transaction in a business method.
  • Sucess - Identify success scenario when a transaction is to be committed.
  • Failed - Identify failure scenario when a transaction is to be rollback.

47.Which are the attributes of Container Managed Security?

EJB 3.0 has specified following attributes/annotations of security which EJB containers implement:

  • DeclareRoles - Indicates that class will accept those declared roles. Annotations are applied at class level.
  • RolesAllowed - Indicates that a method can be accessed by user of role specified. Can be applied at class level resulting which all methods of class can be accessed buy user of role specified.
  • PermitAll - Indicates that business method is accessible to all. Can be applied at class as well as at method level.
  • DenyAll - Indicates that business method is not accessible to any of user specified at class or at method level.

48.What is JNDI? Explain its terms in terms of EJB.

JNDI stands for Java Naming and Directory Interface. It is a set of API and service interfaces. Java based applications use JNDI for naming and directory services. In context of EJB, there are two terms:

  • Binding - This refers to assigning a name to an ejb object which can be used later.
  • Lookup - This refers to looking up and getting an object of ejb.
Explain annotation in EJB to do the database entity relationships/mappings.
EJB 3.0 provides option to define database entity relationships/mappings like one to one, one to many, many to one and many to many relationships. Following are the relevant annotations:
  • OneToOne - Objects are having one to one relationship. For example, a passenger can travel using a single ticket at time.
  • OneToMany - Objects are having one to many relationship. For example, a father can have multiple kids.
  • ManyToOne - Objects are having many to one relationship. For examples, multiple kids having a single mother.
  • ManyToMany - Objects are having many to many relationship. For examples, a book can have mutiple authors and a author can write multiple books.

49.What is EJBQL?

EJB 3.0, ejb query language is quite handy to write custom queries without worrying about underlying database details. It is quite similar to HQL, hibernate query language and is often referred by name EJBQL.

50.What is Application level Exception in EJB?

If business rule is voilated or exception occurs while executing the business logic. Then EJB container treats it as Application level exception.

51.What is System level Exception in EJB?

Any exception which is not caused by business logic or business code. RuntimeException, RemoteException are SystemException. For example, error during ejb lookup.Then EJB container treats such exception as System level exception.

52.How EJB Container handles exceptions?

When Application Exception occurs, ejb container intercepts the exception but returns the same to the client as it is. It does not roll back the transaction unless it is specified in code by EJBContext.setRollBackOnly method. EJB Container does not wrap the exception in case of Application Exception.
When System Exception occurs, ejb container intercepts the exception, rollbacks the transaction and start the clean up tasks. It wraps the exception into RemoteException and throws it to the client.

53.How does EJB support polymorphism?

Because an EJB consists of multiple “parts”, inheritance is achievable in a rather limited fashion (see FAQ answer on inheritance here). There have been noteworthy suggestions on using multiple inheritance of the remote interface to achieve polymorphism, but the problem of how to share method signatures across whole EJBs remains to be addressed. The following is one solution to achieving polymorphism with Session Beans. It has been tried and tested on WebLogic Apps Server 4.50 with no problems so far.
We will use an example to show how it’s done. Say, there are 2 session beans, Tiger and Lion, that share some method signatures but provide different implementations of the methods.

  • AnimalHome and Animal are the home and remote interfaces. The signatures of the polymorphic methods are in Animal.
  • AnimalBean is the base implementation bean.
  • TigerBean and LionBean extend from AnimalBean. They may override the methods of AnimalBean, implementing different behaviors.
  • Deploy Tiger and Lion beans, specifying AnimalHome and Animal as their home and remote interfaces. Note that Tiger and Lion should have different JNDI lookup names.

54.What classes does a client application need to access EJB?

It is worthwhile to note that the client never directly interacts with the bean object but interacts with distributed object stubs or proxies that provide a network connection to the EJB container system. The mechanhism is as follows.

  • The client uses the JNDI context to get a remote reference (stub) to the home object ( the EJBHome).
  • It uses the home to get a remote reference (stub) to the EJBs remote object (the EJBObject)
  • It then invokes business methods on this remote object. The client needs the remote interface, the home interface, the primary key( if it is an entity bean).
In addition to these, the client would need the JNDI factory implementation, and the remote and home stubs. In some EJB servers the Factory and/or stubs can be dynamically loaded at run time. In other EJB servers they must be in the classpath of the client application.

55.What is an EJB primary key? How is it implemented when the database doesn’t have a primary key?

A primary key is an object that uniquely identifies the entity bean. According to the specification, the primary key must be unique for each entity bean within a container. Hence the bean’s primary key usually maps to the PK in the database (provided its persisted to a database). You may need to create a primary key in the database for the sake of referential integrity. This does not, however, mean you NEED a primary key in the database. As long as the bean’s primary key (which maps to a column or set of columns) can uniquely identify the bean it should work.

56.What’s an .ear file?

An .ear file is an “Enterprise Archive” file. The file has the same format as a regular .jar file (which is the same as ZIP, incidentally). The .ear file contains everything necessary to deploy an enterprise application on an application server. It contains both the .war (Web Archive) file containing the web component of the application as well as the .jar file. In addition there are some deployment descriptor files in XML.

57.Is method overloading allowed in EJB?

Yes you can overload methods.

58.How can JMS be used from EJB 1.1?

The same as any client would use JMS. At this point there is no integration, but it is planned for a future release of the EJB spec.

59.Can primary keys contain more than one field?

Yes, a primary key can have as many fields as the developer feels is necessary, just make sure that each field you specify as the primary key, you also specify a matching field in the bean class. A primary key is simply one or more attributes which uniquely identify a specific element in a database. Also, remember to account for all fields in the equals() and hashCode() methods

60.How does Container Managed Persistence work with automatically generated database ID fields? Should I map the ID field explicitly or leave it unspecified?

In the Deployment Descriptor, map the normal fields appropriately, but don’t specify the auto-id field as one of the container managed fields.

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com