Java Reference
In-Depth Information
A
LTERNATIVE
SOLUTIONS
:
The distributed command can also be
used to control round-tripping. Also, refactoring can frequently shift
an interface so that logical tasks are grouped together into a single
physical round-trip. Other alternatives can help performance. A
cache can help after the first load. (Often, both a cache and facade
are desired.) The
EJB
can also be deployed on the same box, though
many times, strong reasons motivate separation.
Round Bean in a Square Hole
R
ELATED
ANTIPATTERNS
:
The Golden Hammer, in
AntiPatterns
.
D
ESCRIPTION
:
Many times, a classification of
EJB
is used inappropriately.
Several different variations of this problem exist. A complex object
relationship may fit bean-managed persistence better than container-man-
aged persistence. In other cases, a problem may not require the full sup-
port of an entity bean. Similarly, entity beans may be overkill for
applications that exclusively read or write.
M
OST
FREQUENT
SCALE
:
Microarchitecture.
R
EFACTORED
SOLUTION
NAME
:
Use the Correct
EJB
for the Job.
R
EFACTORED
SOLUTION
TYPE
:
Software.
R
EFACTORED
SOLUTION
DESCRIPTION
:
The correct bean should be
employed for the application:
For applications having a relationship corresponding to a relational
join (one to many or n-ary relationships), frequently an entity bean
with bean-managed persistence should be employed.
For lightweight functions, session beans have much less overhead
than entity beans.
For write-only applications like system logs or audit trails, files or
JDBC
may be the best choice.
For read-only applications, session beans with
JDBC
or
SQLJ
could
be better choices.
R
OOT
CAUSES
:
Inexperience or apathy.
A
NECDOTAL
EVIDENCE
:
“This development environment builds the
whole model for me automatically. I don't even have to think.”
S
YMPTOMS
,
CONSEQUENCES
:
Applying the wrong bean to a problem
leads to ugly designs or poor performance.