Professional Documents
Culture Documents
Q3
Q3
Q3
A: The transaction attribute specifies how the Container must manage transactions for a
method when a client invokes the method via the enterprise beans home or component
interface or when the method is invoked as the result of the arrival of a JMS message.
(Sun's EJB Specification) Below is a list of transactional attributes:
1. NotSupported - transaction context is unspecified.
2. Required - bean's method invocation is made within a transactional context. If a client
is not associated with a transaction, a new transaction is invoked automatically.
3. Supports - if a transactional context exists, a Container acts like the transaction
attribute is Required, else - like NotSupported.
What
are
transac
tion
isolatio
n levels
in EJB?
A:
1.
Transac
tion_re
ad_unc
ommitt
edAllows a
method
to read
uncomm
itted
data
from a
DB(fast
but not
wise).
2.
Transac
tion_re
ad_com
mittedGuarant
ees that
the data
you are
getting
has
been
committ
ed.
3.
Transac
tion_re
peatabl
e_read
- Guaran
tees that
all reads
of the
databas
e will be
the
same
during
the
transacti
on (good
for read
and
update
operatio
ns).
4.
Transac
tion_se
rializabl
e- All
the
transacti
ons for
resource
are
perform
ed
serial.
Q:
How
EJB
Invocat
ion
happen
s?
A:
Step 1:
Retrieve
Home
Object
referenc
e from
Naming
Service
via
JNDI.
step 2:
Return
Home
Object
referenc
e to the
client.
step 3:
Create
me a
new EJB
Object
through
Home
Object
interface
.
step 4:
Create
EJB
Object
from the
Ejb
Object
step 5:
Return
EJB
Object
referenc
e to the
client.
step 6:
Invoke
business
method
using
EJB
Object
referenc
e.
step 7:
Delegate
request
to Bean
(Enterpri
se
Bean).
Q: Is it
possibl
e to
share
an
HttpSes
sion
betwee
n a JSP
and
EJB?
What
happen
s when
I
change
a value
in the
HttpSes
sion
from
inside
an EJB?
A:
You can
pass the
HttpSess
ion as
paramet
er to an
EJB
method,
only if
all
objects
in
session
are
serializa
ble.This
has to
be
consider
as ?
passedbyvalue",
that
means
that it?s
readonly in
the EJB.
If
anything
is
altered
from
inside
the EJB,
it won?t
be
reflected
back to
the
HttpSess
ion of
the
Servlet
Containe
r.The ?
pass-byreferenc
e? can
be used
between
EJBs
Remote
Interface
s, as
they are
remote
referenc
es.
While it
IS
possible
to pass
an
HttpSess
ion as a
paramet
er to an
EJB
object, it
is
consider
ed to
be ?bad
practice
? in
terms of
object
oriented
design.
This is
because
you are
creating
an
unneces
sary
coupling
between
backend
objects
(ejbs)
and
frontend
objects
(HttpSes
sion).
Create a
higherlevel of
abstracti
on for
your
ejb?s
api.
Rather
than
passing
the
whole,
fat,
HttpSess
ion
(which
carries
with it a
bunch of
http
semantic
s),
create a
class
that acts
as a
value
object
(or
structure
) that
holds all
the data
you
need to
pass
back and
forth
between
frontend/bac
k-end.
Consider
the case
where
your ejb
needs to
support
a nonhttpbased
client.
This
higher
level of
abstracti
on will
be
flexible
enough
to
support
it.
Q: Can the primary key in the entity bean be a Java primitive type
such as int?
A: 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)
Q: What are the special design care that must be taken when you
work with local interfaces?
A: EIt is important to understand that the calling semantics of local
interfaces are different from those of remote interfaces. For example,
remote interfaces pass parameters using call-by-value semantics, while
local interfaces use call-by-reference.
This means that in order to use local interfaces safely, application
developers need to carefully consider potential deployment scenarios up
front, then decide which interfaces can be local and which remote, and
finally, develop the application code with these choices in mind.
While EJB 2.0 local interfaces are extremely useful in some situations,
the long-term costs of these choices, especially when changing
requirements and component reuse are taken into account, need to be
factored into the design decision.
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.