] Head First EJB by Kathy Sierra, Bert Bates The unconfirmed error reports are from readers. They have not yet been approved or disproved by the author or editor and represent solely the opinion of the reader. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification This page was updated February 15, 2008. UNCONFIRMED errors and comments from readers: {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." {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. {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'. (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?" [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. (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" [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." {130} answer, line 3; according to the API documentation, the exception type should be java.rmi.RemoteException [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. {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...". [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. {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()." {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; [225] diagram 1; ejbCreate() missed [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. (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. (241) transactions bullets section; SessionContext's setRollbackOnly method signature differs from j2ee1.3 api book: setRollbackOnly(boolean) api: setRollbackOnly() [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. [249] Q17; Answer provided was: (3) local component matches (c) methods must NOT throw 'java.rmi.RemoteException' (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. (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 [268] Public class declaration; Class should be declared abstract: public abstract class CustomerBean implements EntityBean { {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. {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. {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. {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.) {318} the whole thing; The book says that this is a complete implementation of the CustomerBeanCMP. The ejbPostCreate() method is conspicuously missing! [326] steps 1 and 2; Step 2 should come before step 1 according to OID on page 215 of EJB spec 2.0 {327} Last paragraph; In the 3rd sentence, "need to use a session context," should be "need to use an entity context,". (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." {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(). {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." {381} In Class Movie in the UML Diagram; the method getActors() in class Movie is missing {395} Last Tag; The deployment descriptor should end with a tag (403) 4th line of the lower right notes; ...select method The "/" means the first.... should read as ...select method. The "?" means the first... (408) 2nd paragraph, last line; the word "home" should be changed to "local" (411) First sentence in the first paragraph; In the first line "and let's you put....." should be "and lets you put ......" {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 (429) Question # 15; Answer Option D : it should be 'Input parameters' and not 'Input clauses' [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. [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 [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. (470) Right column, last two lines; In the book: "...you must know that if you invoke getRollbackOnly..." Should be: "setRollbackOnly" [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. (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." (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. [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 (520) 3rd question; It says "Which two are true..." but there are three correct answers. (551) Second diagram; Where it says javax.ejb package it should say javax.transaction package [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 [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. [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)" [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. {564 & 567} question number 5 (answers); The TransactionRolledbackLocalException exception is member of the javax.ejb package and NOT of the javax.transaction package [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. {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." [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. [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. [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. (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. (701) bottom; EJBLocalObject is missing the remove() method.