UNIT 4 5 je
UNIT 4 5 je
1 Write short note on Enterprise Bean Server and Enterprise Bean. (APR 2019)
● An Enterprise Bean Server
o EJB SERVER
o The EJB server (also known as the J2EE application server) is the outermost
container of the various elements that make up an EJB environment. The EJB
server manages one or more EJB containers and provides required support
services, such as transaction management, persistence, and client access. A
JNDI-accessible naming space can be used by clients to locate the EJB.
o 3 tire architecture : ui, business rules, database
o Features : security, threading, connection polling
● Enterprise Bean Containers that runs on these servers
o Manage enterprise bean inside it.
● It provides registration of objects, remote interface, security, transaction
▪ Enterprise Beans that run in these containers
● Its reusable classes (add to cart) logic or emi calculator
▪ Enterprise Bean Clients
● Its standalone application for user interaction (atm machine)
▪ Other systems such as Java Naming and Director Interface [JNDI] and Java
Transaction Service [JTS]
o An EJB component can have remote and local interfaces. Clients not located in
the same application server instance as the bean (remote clients) use the
remote interface to access the bean. Calls to the remote interface require
marshalling arguments, transportation of the marshalled data over the network,
un-marshaling the arguments, and dispatch at the receiving end.
o If an EJB component has a local interface, then local clients in the same
application server instance can use it instead of the remote interface. Using the
local interface is more efficient, since it does not require argument marshalling,
transportation, and un-marshalling.
o Entity Beans
o always have states
o may be shared by multiple EJB Clients
o their states can be persisted and stored across multiple invocations
o survive server shutdown/crash
o encapsulate in their object reference a unique ID that points to their state
2 Describe Packaging of Enterprise Beans in JAR and WAR Modules. (APR 2019)
● Packaging Enterprise Beans
o An EJB JAR file is portable and can be used for various applications.
o To assemble a Java EE application, package one or more modules, such as EJB
JAR files, into an EAR file, the archive file that holds the application. When
deploying the EAR file that contains the enterprise bean's EJB JAR file, you also
deploy the enterprise bean to GlassFish Server. You can also deploy an EJB JAR
that is not contained in an EAR file
Types of interceptors
● Default − Default interceptor is invoked for every bean within
deployment.Default interceptor can be applied only via xml (ejb-jar.xml).
● Class − Class level interceptor is invoked for every method of the bean. Class
level interceptor can be applied both by annotation of via xml(ejb-jar.xml).
● Method− Method level interceptor is invoked for a particular method of the
bean. Method level interceptor can be applied both by annotation of via
xml(ejb-jar.xml).
life cycle of an interceptor
● Interceptor interface defines three methods – init(), destroy() and intercept().
● init and destroy are the life cycle methods of an interceptor.
● Interceptors are Singleton classes and Struts2 initialize a new thread to handle
each request. ● init() method is called when interceptor instance is created and
we can initialize any resources in this method. destroy() method is called when
application is shutting down and we can release any resources in this method.
Interceptor Usage Scenarios
● Request and response logging
● Retrying the requests with a configurable back off strategy
● Request denial based on certain request parameters
● Altering the request URL address
12 Explain the concept of naming service. Add suitable illustration to it.
What is a naming service? (NOV 2022)
● Naming services naming service maintains a set of bindings. Bindings relate
names to objects. All objects in a naming system are named in the same way
(that is, they subscribe to the same naming convention). Clients use the naming
service to locate objects by name.
There are a number of existing naming services
● COS (Common Object Services) Naming: The naming service for CORBA
applications; allows applications to store and access references to CORBA
objects.
● DNS (Domain Name System): The Internet's naming service; maps people-
friendly names (such as www.etcee.com) into computer-friendly IP (Internet
Protocol) addresses in dotted- quad notation (207.69.175.36). Interestingly, DNS
is a distributed naming service, meaning that the service and its underlying
database is spread across many hosts on the Internet.
● LDAP (Lightweight Directory Access Protocol): Developed by the University of
Michigan; as its name implies, it is a lightweight version of DAP (Directory
Access Protocol), which in turn is part of X.500, a standard for network directory
services. Currently, over 40 companies endorse LDAP.
● NIS (Network Information System) and NIS+: Network naming services
developed by Sun Microsystems. Both allow users to access files and
applications on any host with a single ID and password.
13 What is Java Naming and Directory Interface? Explain. (NOV 2019)
What is Java Naming and Directory Interface? Explain. (APR 2023)
● Basic Lookup
● The user of the JNDI client API will first be required to create an initial context
to the naming or directory service to connect to.
● JNDI API defines a context that specifies where to look for an object. The
initial context is typically used as a starting point for all naming and directory
operations.
● An initial context must be created using the specific implementation and extra
parameters required by the implementation. The initial context will be used to
look up a name.
● The named object that is returned by the lookup() method is type casted to
ShoppingCartRemote and then assigned to the ShoppingCartRemote class object
created earlier named cart.
● Resource Injection
o The javax.annotation.Resource annotation is used to declare a reference to a
resource. @Resource can be used in a class, a field or a method.
o With field and method-based injection, the container injects the resource
when the application is initialized. For class-based injection, the resource is
looked up by the application at runtime.
@Resource
private MessageDrivenContext mdc;
A Message-Driven Bean is injected by a MessageDrivenContext resource. This
resource is commonly used to call the setRollbackOnly() method to handle
exceptions for a bean that uses container-managed transactions.
Unit 51 What is Persistence? Explain. (NOV 2019)
or
Write a note on Java Persistent API. (APR 2023)
● What Is Persistence?
● Most business applications require that data must be persistent. Data can be
labeled as persistent only when it manages to survive day to day problems such
as system crashes and network failures.
● In enterprise application architecture, data persistence is implemented as:
o Having data stored outside an application's active memory, known as
persistent data store, typically a relational database or an object database or a
flat file system Having a rollback system, where, in case of system failure, the
state of the data is rolled back to its last known valid data state.
o Large amounts of data should not be stored in an HTTP session, instead a
database should be considered.
o The type of database that is chosen also plays an important influence on the
architecture and design.
● Persistence In Java
● Persistence in Java usually means storing data in a relational database using
SQL.
● In Java, persistence is accomplished by storing data in a Relational Database
Management
● System [RDBMS]. SQL is used to get data in and out of the relational database.
● Java DataBase Connectivity [JDBC] - The Java API is used to connect to the
RDBMS and fire SQL statements.
● Object Oriented Programming is based on OBJECTS that represent the
business model [the real world]. Objects are easily traversed through
relationship graphs using inheritance, associations.
● Object Persistence deals with persistence in object oriented programs such as
Java. It means determining how objects and their relationships are persisted in a
relational database.
● Object persistence is about
o Mapping object state
o Determining how an object's state [data stored in member variables of an
object] is stored in database table columns
o Dealing with the fact that object state types may not align with relational
database types
o Mapping object relationships
Telegram | youtube | Android App | website | instagram | whatsapp | e-next
For detailed Video Lecture Download The Shikshak Edu App
o Determining how associations between objects are stored as relational
database keys
or in relational database intersection tables
● Why Object Oriented Models?
● Business logic can be implemented in Java as opposed to stored procedures
● Design patterns and sophisticated object oriented concepts such as
inheritance and
● polymorphism can be used
● Provides code reusability and maintainability.
In most of the applications, storing and retrieving information usually involves
some kind of
interaction with a relational database
● Why Relational Database?
● A relational database is a choice because of the following:
o It is a proven data persistence technology
o Provides flexible and robust approach to data management
o It is the De-facto standard in software development
● The Java Persistence API
● The Java Persistence API is a standard API that allows accessing, persisting and
managing data
between Java objects / classes and the relational database in Java EE 5 platform.
● JPA provides standard mechanisms to using Object Relational Mapping tools.
● Java Persistence consists of three areas:
o The Java Persistence API
o Object/Relational mapping metadata
o The Query language
● Object-relational mapping with the Java Persistence API is entirely metadata
driven.
● It can be done by:
o Adding annotations to the code spec OR
o Using externally defined XML OR
o Using annotations as well as externally defined XML
2 Explain the persistent standards available in java. (NOV 2018)
What is Impedance Mismatch? How it can be solved? (NOV 2018)
What is The Impedance Mismatch? How it can be solved? (APR 2019)
Define Impedance Mismatch. What is a solution to the Impedance Mismatch?
● Why Another Persistence Standards
o The object oriented [domain] model use classes whereas the relational
databases use tables. This creates a gap [The Impedance Mismatch].
o Getting the data and associations from objects into relational table structure
and vice versa requires a lot of tedious programming due to the difference
between the two.
o This difference is called The Impedance Mismatch.
o Developers need something simple to convert from one to the other
automatically.
o Bridging the gap between the object model and the relational model is known
as Object- Relational Mapping [O-R mapping or ORM].
o The Impedance Mismatch
▪ Relational databases are structured in a tabular manner and the object
oriented instances are structured in a hierarchical manner.
o How To Map One To The Other?
▪ The most native approach that is usually taken is a simple mapping between
each class and the database table. This approach requires writing a lot of code
spec that maps one to the other. This code spec is often complex, tedious and
costly to develop.
o The Solution To The Impedance Mismatch
▪ This impedance mismatch has led to the development of several different
object persistence technologies attempting to bridge the gap between the
relational world and the object oriented world.
▪ Hence the solution is:
● Use an Object Relational Mapping Tool.
● An Object Relational Mapping Tool provides a simple API for storing
and retrieving Java objects directly to and from the relational database
● Object/Relational Mapping [ORM] is a technique that allows an
application written in an object oriented language to deal with the
information [it manipulates] as objects, rather than using database
specific concepts such as ROWS, COLUMNS and TABLES which is
facilitated by a software called Object/Relational Mapper.
● Object/Relational Mapper also offers persistence services [CRUD]
● O/R mapping is performed by a persistence framework.
● This framework knows how to:
o Query the database to retrieve objects
o Persist those objects back to their representation in the
database's tables and columns
▪ ORM has several benefits.
● Eliminates writing SQL to load and persist object state, leaving the developer
free to concentrate on the business logic
● Enables creating an appropriate DOMAIN model, after which, the developer
only needs to think in terms of OBJECTS, rather than TABLES, ROWS and
COLUMNS
● Reduces dependence on database specific SQL and thus provides Portability
across databases
● Reduces more than 30% of the amount of Java code spec that needs to be
written by adopting an ORM
● Persistence
o The javax.persistence.Persistence class contains static helper
methods to obtain EntityManagerFactory instances in a vendor-
neutral fashion.
● EntityManagerFactory
o The EntityManagerFactory is created with the help of a Persistence
Unit during the application start up. It serves as a factory for spawning
EntityManager objects when required.
o Typically, it is created once [one EntityManagerFactory object per
database] and kept alive for later use.
● EntityManager
o The EntityManager object [javax.persistence.EntityManager] is
lightweight and inexpensive to create. It provides the main interface
to perform actual database operations.
o All the POJOs i.e. persistent objects are saved and retrieved with the
help of an EntityManager object.
o Typically, EntityManager objects are created as needed and
destroyed when not required.
o Each EntityManager manages a set of persistent objects and has
APIs to insert new objects and delete existing ones.
● Entity
o Entites are persistent objects that represent datastore records.
● EntityTransaction
o A Transaction represents a unit of work with the database.
o Any kind of modifications initiated via the EntityManager object are
placed within a transaction. An EntityManager object helps creating
an EntityTransaction object.
o Transaction objects are typically used for a short time and are closed
by either
committing or rejecting.
● Query
o Persistent objects are retrieved using a Query object.
o Query objects [javax.persistence.Query] allows using SQL or Java
Persistence QueryLanguage [JPQL] queries to retrieve the actual data
from the database and create objects.
● Criteria
o Criteria API is a non-string-based API for the dynamic construction of
object-based queries [javax.persistence.criteria].
o Just like JPQL static and dynamic queries, criteria query objects are
passed to the EntityManager's createQuery() method to create Query
objects and then executed using the methods of the Query API.
o WHERE clause predicates
o SELECT clauses, which comprise one or more select item objects
o ORDER-BY and GROUP-BY items
o Subqueries
6 What is the relationship between JPA, ORM, Database and the application?
(APR 2019)