Skip to content

Instantly share code, notes, and snippets.

@kranthilakum
Last active February 27, 2018 09:20
Show Gist options
  • Save kranthilakum/5a67ead6f3094adb9a6bf970e52c7e43 to your computer and use it in GitHub Desktop.
Save kranthilakum/5a67ead6f3094adb9a6bf970e52c7e43 to your computer and use it in GitHub Desktop.
Enterprise JavaBeans Technology

Enterprise JavaBeans Technology

  • server-side component architecture for Java Platform, Enterprise Edition (Java EE)
  • enables rapid and simplified development of distributed, transactional, secure and portable applications based on Java technology
  • JSR 220 FR: EJB 3.0 Documentation/Specification
    • defines EJB API for development of enterprise applications
    • defines dependency injection facility
    • defines query language for Java Persistence that is an extension to EJB QL
    • introduces Java language metadata annotations to be used as an alternative to deployment descriptors
    • defines metadata annotations and XML deployment descriptor elements for the object/relational mapping of persistent entities
    • provides an interceptor facility for session beans and message-driven beans

EJB Programming Model

  • developer uses enterprise bean class as the primary programming artifact

  • developer defines enterprise bean class and annotates it using Java metadata annotations

  • bean type of enterprise bean class must be specified by means of metadata annotations; otherwise deployment descriptor elements may be used

  • session beans and message-driven beans require a business interface

  • business interface of an enterprise bean is a plain Java interface

  • business interface of a message-driven bean is typically defined by the messaging type used (e.g. javax.jms.MessageListener in the case of JMS)

  • The bean class may implement its business interface(s). A bean class may have more than one business interface

  • While it is expected that the bean class will typically implement its business interface(s), if the bean class uses annotations on the bean class or the deployment descriptor to designate its business interface(s), it is not required that the bean class also be specified as implementing the interface(s).

Rules which apply when defining a bean class:

  • if bean class implements a single interface, that interface is assumed to be the local business interface of the bean unless the interface is designated as a remote business interface by use of the Remote annotation on the bean class or interface or by means of the deployment descriptor
  • if bean class has more than once business interface (other than java.io.Serializable; java.io.Externalizable; or any of the interfaces defined by javax.ejb package), that interface must be explicitly designated as a business interface of the bean by means of Local or Remote annotation on the bean class or interface or by means of the deployment descriptor
  • same business interface cannot be both a local and a remote business interface of the bean (class). It is also an error if @Local and/or @Remote is specified both on the bean class and on the referenced interface and the values differ.
  • business interface must not extend javax.ejb.EJBObject or javax.ejb.EJBLocalObject

Interceptors

  • interceptors may be defined for session beans and message-driven beans
  • interceptor is a method to intercept a business method invocation or a lifecycle callback event
  • interceptor method may be defined on bean class or an interceptor class associated with the bean
  • interceptor class is a class whose methods are invoked in response to business method invocation and/or lifecycle events on the bass class

Notes

  • JSR-175 specification of J2SE 5.0 allows developers to annotate program elements in Java programming language source files to control the behavior and deployment of an application.
  • Why do you need annotations/metadata? -
  • Metadata annotations are a key element in the simplification of the development of EJB applications. They are used by the developer to specify expected requirements on container behavior, to the request injection of services and resources, and to specify object/relational mappings. They might be used as an alternative to the deployment descriptors. However, it is not required that metadata annotations be used in EJB 3.0 application. Developers who prefer the use of a deployment descriptor as an alternative to metadata annotations may define one for this purpose. It is possible for the application developer to combine the use of metadata annotations and deployment descriptors in the design of an application. When such a combination is used, the rules for the use of deployment descriptors as an overriding mechanism apply
  • The metadata annotations to specify that a bean implements a web service and how the web service is exposed to clients are defined by JSR-181, “Web Services Metadata for the Java Platform.”

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment