Errata

Head First EJB

Errata for Head First EJB

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page xxiv
3rd bullet

J2EE SDK *does* include the API doc. See

http://java.sun.com/j2ee/1.3/download.html

"Note:The API documentation for the J2EE SDK v1.3.1 is packaged with the download bundle."

Anonymous   
Printed Page 3
local component matches (c) methods must NOT throw 'java.rmi.RemoteException'

Anonymous   
Printed Page 4
local home matches (d) can be used to retrieve an EJBLocalObject

According to the API, EJBLocalHome interface contains only ONE single method, i.e.,
remove(Object primaryKey). Also, the EJBLocalObject interface contains a
getEJBLocalObject method. Hence, the answers should be (3) -> (d) & (4) -> (c)
instead.

Anonymous   
Printed Page 60
first paragraph (handwriting to mock exam answers)

The handwriting indicating where to find the specific theme in the specs says it
would be page 30 of the specification. Actually this should point to page 493 of the
ejb 2.0 specification me thinks.

Anonymous   
Printed Page 60
mock exam answers - 3rd question answer - B

The answer 'B' (Container managed persistence) is ticked in the book. But Container
managed persistence is not a new feature in EJB2.0. I think it should be 'Container
managed relationships'.

Anonymous   
Printed Page 61
paragraph at bottom

The sentence "How does the client call methods it?" is obvously missing some words.
Perhaps it should be saying "How does the client call methods ON it?"

Anonymous   
Printed Page 71
Lower right diagram.

Shouldn't the method invocation to the Remote Dog object be "trainPet(myDog)", not "trainPet(newDog)"?

Eric Larson  May 11, 2010 
Printed Page 82
1st paragraph from the bold notes on the right column

In page 82 it is stated that Remote Object(and according to the picture of this page
Remote Object=EJBObject) implemnts Component Interface, but this is opposite to the
page 83 when it says:
Remote Component interface must extends the EJBObject interface.

I know the concept here(some contradiction with core java!), and I think the picture
should be corrected(Remote Object != EJBObject)
EJBObject is an interface while Remote Object is an object.

Anonymous   
Printed Page 104
Sharpen your pencil True and False questions

The last True or False question -
"Each entity bean must have its EJBObject"
should read
"Each entity bean must have its OWN EJBObject"

Anonymous   
Printed Page 126
last paragraph

"There's only one interface here that could be a stateless session
bean's home-number 3."
should read:
"There are two interface here that could be a stateless session
bean's home-number 1 and 3. And number 1 could be both stateless and stateful."

Anonymous   
Printed Page 130
answer, line 3

according to the API documentation, the exception type should be
java.rmi.RemoteException

Anonymous   
Printed Page 139
code snippet at bottom of page

I think that the line
Object o = h.getEJBObject(); should read
EJBObject o = h.getEJBObject();
since getEJBObject returns and EJBObject not just a regular object.

Anonymous   
Printed Page 153
First paragraph

It says: "If local home interfaces don't have handles, then there's no way...".

It should say: "If local component interfaces don't have handles, then there's no
way...".

or perhaps: "If locally-exposed beans don't have handles, then there's no way...".

Anonymous   
Printed Page 170
3rd Question

In the first line of this question it was stated that remote client R has valid references to session beans 'A' and 'B'. But from the following line we can understand that 'A' has a local reference for 'B'. That means 'B' must be a local bean (extends local component interface and local home interface). Then how can 'R', a remote client, have a valid reference for 'B'?

The description of this question must modified as:
Given a remote client 'R', that has a valid reference to session bean 'A', and given that 'A' is a local client to session bean 'B'.

Anonymous  Sep 26, 2008 
Printed Page 171
Question 5 : Choice C.

Question 5, choice C states: "The remove() method in the component
interface can be used only by remote clients." Handwriting next to
it says: "- no, only for local".

I agree that the statement is not correct, but the comment is wrong.
Choice C. is incorrect because the remove() method in the component
interface can be used by both remote AND local clients, and not by
local only. This can be verified on page 154. Also, on page 137, it
is stated in bullet 4 that remote clients can call remove() on the
component interface as good manners to tell the container your're
done.

Anonymous   
Printed Page 188
Top of page, bean's "thinking balloon"

It reads, "...by giving me a context and calling my create()."

It should read, "...by giving me a context and calling my ejbCreate()."

Anonymous   
Printed Page 203
bottom of page in the main method of AnimalTestDrive class

The first line of the main method reads:

AnimalTestDrive list = new AnimalTestDrive();

it should read;

MyAnimalList list = new MyAnimalList;

Anonymous   
Printed Page 225
diagram 1

ejbCreate() missed

Anonymous   
Printed Page 228
ejbCreate,ejbRemove list

in the list of things you can do from stateless bean methods there is an omission.
From a stateless session bean with BMT it is possible to get a transaction reference
using getUserTransaction, spec 90. So it should say that its about CMT stateless
session bean.

Anonymous   
Printed Page 232
1st paragraph, 1st line

In the book: "Local home interfaces must return... Remote home interfaces must return...".
Strictly speaking, interfaces don't return anything, but rather methods return something.

Anonymous   
Printed Page 241
transactions bullets section

SessionContext's setRollbackOnly method signature differs from j2ee1.3 api

book: setRollbackOnly(boolean)
api: setRollbackOnly()

Anonymous   
Printed Page 249
Q17

Answer provided was:

Anonymous   
Printed Page 252
Question 6

Which session bean interface can contain this method?

Provided answer is A. However, SessionBean interface does not contain such a method
at all. Even the SessionBean interface's implementation class doesn't - it contains
ejbCreate method(s) instead.

So the answer should be D.

Anonymous   
Printed Page 268
last 3rd line

ejbFindPrimaryKey should be changed to ejbFindByPrimaryKey

(answer for p.317) ejbCreate and ejbPostCreate;
The number of arguments in ejbCreate and ejbPostCreate must same as the create

Anonymous   
Printed Page 268
Public class declaration

Class should be declared abstract:

public abstract class CustomerBean implements EntityBean {

Anonymous   
Printed Page 291
Hand-written comment with answer 3A

Besides the comment 'we said existing :)', it should also be noted that ejbCreate
cannot be called directly by the client. It is called by the container.

Anonymous   
Printed Page 292
Hand-written comment with answer 5A

Besides the comment 'we said EXISTING', it should also be noted that ejbCreate cannot
be called directly by the client. It is called by the container.

Anonymous   
Printed Page 292
Question 6

The explanation for answer B is not entirely correct. If two keys pass the equals()
test, it is not guaranteed that they point to the same entity. The spec (p. 120) says
that 'it is possible that multiple entity beans use the same primary key class'. This
means it's also possible that two equal primary key instances point to two different
entities from different entity beans. Of course this would be a very large
coincidence that will never happen.

Anonymous   
Printed Page 312
CustomerBean methods

The home interface defines four methods: create(), findByPrimaryKey(), findByCity() and updateAll(). The "notes" on the left side of the page states that "You must match every home business method with an ejbHome<methodName>". The CustomerBean in the center column shows that updateAll() has the corresponding method ejbHoneUpdateAll() but the two find methods have the same names as in the CustomerHome interface. Shouldn't they also be ejbHomeFindByPrimaryKey() and ejbHomeFindByCity()?

Anonymous  Dec 14, 2011 
Printed Page 316, 318
ejbCreate()

ejbCreate() calls the virtual field setters for last name, first name, and primary
key, but then calls the non-virtual setter for address. (It all works out; the non-
virtual setter then calls the virtual setter for address.)

Anonymous   
Printed Page 318
the whole thing

The book says that this is a complete implementation of the CustomerBeanCMP. The
ejbPostCreate() method is conspicuously missing!

Anonymous   
Printed Page 326
steps 1 and 2

Step 2 should come before step 1 according to OID on page 215 of EJB spec 2.0

Anonymous   
Printed Page 327
Last paragraph

In the 3rd sentence, "need to use a session context," should be "need to use an
entity context,".

Anonymous   
Printed Page 345
Item 3, page 345.

"A bean is selected from the pool to run the ejbUpdateAll() method."

According to the implementation, it should be

"A bean is selected from the pool to run the ejbHomeUpdateAll() method."

Anonymous   
Printed Page 355
order of ejbPassivate() and ejbStore() in the timeline

On page 352 it says that the "Container always calls ejbStore() before
ejbPassivate()", yet on page 355 the timeline reverses this order. Page 355's
timeline says that ejbPassivate() precedes ejbStore().

Anonymous   
Printed Page 370
Question 13, Item C

Says "C. All fields in the primary key class must be declared public."
should say "C. All fields in the primary key class using multiple fields must be
declared public."

Anonymous   
Printed Page 381
In Class Movie in the UML Diagram

the method getActors() in class Movie is missing

Anonymous   
Printed Page 395
Last Tag

The deployment descriptor should end with a </ejb-jar> tag

Anonymous   
Printed Page 403
4th line of the lower right notes

...select method The "/" means the first....
should read as
...select method. The "?" means the first...

Anonymous   
Printed Page 408
2nd paragraph, last line

the word "home" should be changed to "local"

Anonymous   
Printed Page 411
First sentence in the first paragraph

In the first line "and let's you put....." should be "and lets you put ......"

Anonymous   
Printed Page 428
question 11

according to the EJB 2.0 specification, a cmr-field must begin with a lowercase
letter, so the c.Order in EJB-QL should be c.order

Anonymous   
Printed Page 429
Question # 15

Answer Option D :

it should be 'Input parameters' and not 'Input clauses'

Anonymous   
Printed Page 432
Question 4

The answer mentions B as correct (b2.getFoo() == null). But as the CMR relationship
is said *unidirectional*, b2.getFoo() does not even exist. A (f1.getBar() == null)
should be the only correct answer.

Anonymous   
Printed Page 432
Answer B for the question number 4

The question states "unidirectional relationship". So, I think, Bar simply does not
have getFoo() method. Answers B and C are invalid

Anonymous   
Printed Page 434
Question 12

Answer D is incorrect.
The question is "Which will return all orders that have line items ?".

D = SELECT OBJECT(o) FROM Order o

Or there is a missing "WHERE NOT o.lineItems IS EMPTY" or D should be unchecked.

Anonymous   
Printed Page 470
Right column, last two lines

In the book: "...you must know that if you invoke getRollbackOnly..."

Should be: "setRollbackOnly"

Anonymous   
Printed Page 504
2 paragraph, example

Under "Option2", in the example, in the first container-transaction element there are
three methods with three different ejb-name values. It means that these methods
belong to different beans.

On the other hand EJB spec on the page 353 says: "It is required that all the methods
specified in a single container-transaction element be methods of the same enterprise
bean". It means that the example doesn't comply to the spec.

Anonymous   
Printed Page 508
fifth point

"Can be used to keep a transaction open across multiple invocations to a stateful method bean."
should be:
"Can be used to keep a transaction open across multiple invocations of a stateful -session- bean."

Anonymous   
Printed Page 514,515
Inside the pool diagram

inside the pool diagram
c.cmtMandatory); should be c.cmtMandatory();
another one
c.cmtMandatory()); should be c.cmtMandatory();

Same things should also be changed in the solution on 515.

Anonymous   
Printed Page 515
Answer to the Puzzle

The answer is valid for stateless session beans, isn't?

The sequence ut.begin(); c.cmtRequiresNew(); c.cmtMandatory(); c.cmtRequiresNew();
ut.commit() will result in exception at attempt to call the second cmtRequiresNew().
It would mean that the same instance of the bean keeps pending changes from
cmtMandatory() and is asked to start new transaction. As I understand, it will not
work

Anonymous   
Printed Page 520
3rd question

It says "Which two are true..." but there are three correct answers.

Anonymous   
Printed Page 551
Second diagram

Where it says javax.ejb package
it should say javax.transaction package

Anonymous   
Printed Page 551
remote client will get these (checked)

TransactionRolledBackException and TransactionRequiredException are in
javax.transaction, NOT javax.ejb, only their Local counter parts come from javax.ejb

Anonymous   
Printed Page 559
2nd paragraph

In the book:

The client gets a RemoveException. Why? Because the only remove() method in a session
bean's local home is the one that takes a primary key, and that can never work.
Remote client would also get a RemoveException.

Should read:

The client gets an EJBException. ... Remote client would get a RemoteException.

Anonymous   
Printed Page 559
4th paragraph, 2nd line

"(if the client were local, he'd get a RemoteException)"
It should be
"(if the client were remote, he'd get a RemoteException)"

Anonymous   
Printed Page 560
!st paragraph

"A session bean calls getPrimaryKey() on its context ...
bean gets an Illegal state exception.

This is incorrect, as sessionContext has no getPrimaryKey() method - only
entityContext has getPrimaryKey() which can throw an illegalStateException.

If the author meant "call getPrimaryKey() via the EJBObject" then the exception would
be a remoteException, not an IllegalStateException.

Anonymous   
Printed Page 564 & 567
question number 5 (answers)

The TransactionRolledbackLocalException exception is member of the javax.ejb package
and NOT of the javax.transaction package

Anonymous   
Printed Page 596
Question 2

Option B checked as a correct answer. It says: "They can be listed in the unchecked element."

In EJB spec (p.485) element unchecked defined as EMPTY, which means that nothing can
be listed in it.

Anonymous   
Printed Page 611
4th line from the bottom

The line gives Bean as a value of res-auth element

EJB spec. (p. 423) says: "The Bean Provider indicates the sign-on responsibility by
setting the value of the res-auth element to Application or Container."

Anonymous   
Printed Page 636
question 16 answer A

If an ejb-jar file only contains message-driven beans, then it does not contain any home or component interface.

Anonymous   
Printed Page 672
Question 46, option A

Option A says: "Primary key fields must be cmp-fields." The handwritten comment says:
"... you can use a compound key", implying that the option is not correct.

Because the option says about fields of a primary key, it must mean the primary "key
that maps to multiple fields in the entity bean class." (spec p.203), which means
that the primary key is a compound key. That makes the comment out of place and the
option as a correct answer.

Anonymous   
Printed Page 673
Ques 49

answer choice c:
C. Entity beans with BMT demarcation must use the getStatus method instead of the getRollBackOnly method.
- is wrong because entity beans are not allowed to use BMT.

Anonymous   
Printed Page 675
Question 55

The question starts with: "When creating an entity bean..."

"Creating" can be applied either to the life cycle of the bean or to "providing" the
bean by the Bean Provider. The options of the question are not applicable to either
case, but rather to "using" the bean.

Anonymous   
Printed Page 701
bottom

EJBLocalObject is missing the remove() method.

Anonymous