Professional Documents
Culture Documents
Black Belt SCBCD
Black Belt SCBCD
2 Author
1 Introduction Liesbeth Jaco is a Java instructor at Loop Factory,
1.1 Why this document? Belgium. She moderates the EJB and WebSphere
sections at JavaBlackBelt.com.
Together with the “Head First EJB” book and the Sun EJB version 2.0
Specification, this study guide should help you to become fully prepared for the
SCBCD certification exam. She will be happy to get your feedback about this
document by email: Liesbeth <at} JavaBlackBelt dot com
+ + +
3 Reviewers
This study guide has been kindly reviewed by …
The basis of this document was written when I studied for the SCBCD Valentin Crettaz has a Masters degree in Information and Computer
Science from the Swiss Federal Institute of Technology in Lausanne
certification myself. I felt that next to the clear explanations of “Head First EJB”, (EPFL). He has worked as a software engineer with SRI International
the summarizing bullet points, recap exercises and mock questions, I needed a (Menlo Park, CA) and as a principal engineer in the Software
more concise, structured document to allow me to have an overview and have a Engineering Laboratory of EPFL.
quick, last-minute check of some difficult sections. Kind of like Valentin Crettaz’s Valentin is the co-founder and CTO of Condris Technologies, a
cheat sheets I found on JavaRanch. Other “summaries” were sometimes too company specializing in the development of next generation software
wordy and elaborate, and not structured enough to serve as a real study guide. architecture solutions.
Recently, I taught a class of students with the purpose of obtaining the EJB His research and development interests include aspect-oriented
certification. As I used “Head First EJB” in my course material, I got the same technologies, design and architectural patterns, web services, and software architecture.
remarks from the students about it as I made myself, which encouraged me to During his spare-time, Valentin moderates the SCBCD and SCDJWS forums at
Javaranch.com and acts as a technical reviewer for O'Reilly's Head First series. He holds
transform my personal notes into this complete studyguide.
various Sun and IBM certifications, such as SCJP, SCJD, SCBCD, SCWCD, SCDJWS and
IBM XML. He has also had the great opportunity to serve as a co-author for Whizlabs'
1.2 How to use it? SCBCD and SCDJWS Exam Simulators.
As introduced, this document should not be used as a standalone study guide. John Rizzo is cofounder and managing director of Loop Factory, a Java
First of all, I assume that you already have an understanding of EJB - by reading focused education company.
“Head First EJB” or a similar book. Secondly, I often refer to the HF book, e.g. He has spent the last decade teaching IT; from OO to Java, going
for a concrete example, for additional theory that was not easy to summarize, or through AS/400 systems, methodologies and Delphi; to professionals,
when the book contains a nice structured summary anyway. So the purpose of unemployed and children.
these notes is not to replace this book, but to be a guide-book. John has co-founded JavaBlackBelt.com, a web site dedicated to
technical quizzes about Java related technologies.
Session Entity
Message 4 Interfaces to Memorize
Driven
See Interfaces Schema for the methods of following interfaces
Remote You must know when certain methods cannot be called!
page 58, 6.3 page 111, 9.5
EJBHome • EJBHome
Home interface
Local - remove(Object PK) for SB: RemoveException
page 60, 6.4 page 114 , 9.6
EJBLocalHome • EJBLocalHome
Remote - remove(Object PK) for SB: RemoveException
page 121, 9.9
Component EJBObject • EJBObject
page 61, 6.5
interface Local
page 122, 9.10 - getPrimaryKey() for SB: RemoteException
EJBLocalObject • EJBLocalObject
• Memorize methods: see Interfaces Schema - getPrimaryKey() for SB: EJBException
2 Client Lookup
You have to know the syntax of a lookup and must recognize whether a client is
local or remote.
3 Handles
• Serializable representation of component or home interface, that knows how to
get back to the original Remote object (getEJBObject(), getEJBHome())
• Page 139 [HFEjb]
11.3 Examples
… which show the use of following keywords…
• SELECT and FROM: mandatory
- Page 409 [HFEjb]
- DISTINCT: returned Collection contains no duplicates
• WHERE: pages 411-412 [HFEjb]
• IN: pages 415 + 417 [HFEjb]
• BETWEEN: page 416 [HFEjb]
- Inclusive, NOT BETWEEN is exclusive!
• IS EMPTY, NOT EMPTY page 418 [HFEjb]
• LIKE, NOT LIKE page 419 [HFEjb]
12 Lifecycles
See Lifecycles Schema
13 Interfaces to Memorize
See Interfaces Schema: Methods of following interfaces
• EntityBean
• EntityContext
2 Message Acknowledgment
See Transactions-section
3 MessageDrivenContext
• Methods from EJBContext interface, no additional methods in
MessageDrivenContext: see Interfaces Schema
• Know what you can call under which circumstances: see WhatyouCanCall
Schema
4 Lifecycle
See Lifecycles Schema
5 Interfaces to Memorize
See Interfaces Schema: Methods of following interface
• MessageDrivenBean
• javax.jms.MessageListener
2 Responsibilities
2.1 Bean provider responsibilities
• If you catch or create an application exception, throw it to container as
application exception
- If you find you can’t continue transaction, call setRollbackOnly() first
• If business logic throws an exception the client does not expect, catch it and
rethrow it as EJBException
• Don’t catch runtime exception in business logic, just propagate it
• Application exception must be declared in client interface and bean class
• When creating own application exceptions: extend Exception
- NOT RuntimeException or RemoteException
3 Scenarios
Read example scenarios: pages 558-560 [HFEjb]
• Exception Summary
• Transaction Summary
• Bean Class Schema
• Interfaces Schema
• Lifecycles
• What You Can Call
• DD Schema
1 Application Exceptions
java.rmi. javax.ejb. javax.ejb.
NoSuchObjectException TransactionRequiredException TransactionRolledbackException
Checked! java.lang.
Exception
javax.ejb. javax.ejb.
DuplicateKeyException ObjectNotFoundException
ejbActivate() ; ;
ejbPassivate() ; ;
ejbLoad() ;
ejbStore() ;
unsetEntityContext() ;
ejbCreate() Required Required
At least one Optional
Creation
busMethXxx(…)
Business Logic? onMessage(Message) busMethXxx(…)
ejbHome<METHOD>(…)
afterBegin()
SessionSynchronization beforeCompletion()
afterCompletion(boolean)
abstract
Persistent state? getter/setter Not in
Certification
Not implemented,
Objectives
nor declared.
finders (generated from
EJB-QL in DD)
abstract
selectors ejbSelectXxx
Remark: Gray areas mean that the option is not applicable in the given context.
javax.e jb.EJBH o me javax.ejb .EJBObje ct javax .ejb.E JB Lo calHo m e javax.ej b.EJBL oca lObject
getEJ BMetaD ata() get EJBH ome() remove(Objec t PK) getEJ BLocalH ome()
getH omeH andle() get Handle() getPrimaryK ey()
rem ove(H andle) get Prim aryKey() isIdentic al(EJ BLocalOb ject)
rem ove(O bject P K) isIdentical(E JBO bject)
remove()
javax.e jb.En tityBean javax.ejb .Session Bean javax.ejb .MessageD riven Bean
javax.transaction .
U serT ransaction
begin()
comm it()
getStatus()
rollback()
setR ollback Only()
javax.ejb.
Session Syn chro niz atio n
afterBegin()
beforeC om pletion()
afterC ompletion(b oolean)
ejbPostCreate context.
; getEJB(Local)Home
; getEJB(Local)Object
; getPrimaryKey()
; isCallerInRole(s)/getCallerPrincipal()
; setRollbackOnly (CMT)
; getRollbackOnly(CMT)
- getUserTransaction (BMT)
access
; java:comp/env
; other bean’s methods
; resource manager
Business method context. context. context. context.
- for SB, EB: from ; getEJB(Local)Home ; getEJB(Local)Home ; getEJB(Local)Home ; setRollbackOnly (CMT)
comp interface ; getEJB(Local)Object ; getEJB(Local)Object ; getEJB(Local)Object ; getRollbackOnly(CMT)
- for MDB: ; isCallerInRole(s)/getCallerPrincipal() ; isCallerInRole(s)/getCallerPrincipal() ; isCallerInRole(s)/getCallerPrincipal() ; getUserTransaction (BMT)
onMessage ; setRollbackOnly (CMT) ; setRollbackOnly (CMT) ; setRollbackOnly (CMT)
; getRollbackOnly(CMT) ; getRollbackOnly(CMT) ; getRollbackOnly(CMT) access
; getUserTransaction (BMT) ; getUserTransaction (BMT) - getUserTransaction (BMT) ; java:comp/env
access access access ; other bean’s methods
; java:comp/env ; java:comp/env ; java:comp/env ; resource manager
; other bean’s methods ; other bean’s methods ; other bean’s methods
; resource manager ; resource manager ; resource manager
Home business context.
method ; getEJB(Local)Home
- getEJB(Local)Object
- getPrimaryKey()
; isCallerInRole(s)/getCallerPrincipal()
; setRollbackOnly (CMT)
; getRollbackOnly(CMT)
- getUserTransaction (BMT)
access
; java:comp/env
; other bean’s methods
; resource manager
ejbActivate context. context.
ejbPassivate ; getEJB(Local)Home ; getEJB(Local)Home
; getEJB(Local)Object ; getEJB(Local)Object
; isCallerInRole(s)/getCallerPrincipal() ; getPrimaryKey()
- setRollbackOnly (CMT) - isCallerInRole(s)/getCallerPrincipal()
- getRollbackOnly(CMT) - setRollbackOnly (CMT)
; getUserTransaction (BMT) - getRollbackOnly(CMT)
access - getUserTransaction
; java:comp/env access
; other bean’s methods ; java:comp/env
; resource manager - other bean’s methods
- resource manager
ejbLoad context.
ejbStore ; getEJB(Local)Home
; getEJB(Local)Object
; getPrimaryKey()
; isCallerInRole(s)/getCallerPrincipal()
; setRollbackOnly (CMT)
; getRollbackOnly(CMT)
- getUserTransaction (BMT)
access
; java:comp/env
; other bean’s methods
; resource manager
Lifecycles
e ejbFindXxx
ivat pooled
ready ass or ejbSelectXxx
ejbP or ejbHomeXxx
ejbCreate
ejbPostCreate
ejbActivate ejbRemove
orejbPassivate
business methods
ejbLoad ejbSelect
ejbStore ready
Bean Provider
Application Assembler
Deployer
Bold: Mandatory elements
Red: Default values
<resource-ref> <!--optional-->
<description>Some DataSource description</description>
<res-ref-name>jdbc/SomeDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container / Application</res-auth>
<res-sharing-scope>Shareable / Unshareable</res-sharing-scope>
</resource-ref>
<resource-env-ref> <!--optional-->
<description>Some DataSource description</description>
<resource-env-ref-name>jms/SomeQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
<security-role-ref> <!--optional-->
<description>Security role reference description</description>
<role-name>Manager</role-name>
<role-link>Administrator</role-link>
</security-role-ref>
<security-identity> <!--optional-->
<description>Security identity description</description>
<run-as>
<description>Run as description</description>
<role-name>Manager</role-name>
</run-as>
OR
<use-caller-identity />
</security-identity>
<query> <!--optional-->
<description>Query description</description>
<query-method>
<method-name>findSomething</method-name>
<method-params> <!--optional-->
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<result-type-mapping>Local / Remote</result-type-mapping>
<ejb-ql>SELECT OBJECT(e) FROM EntityBean e WHERE e.field1 = ?1</ejb-ql>
</query>
</entity>
Bean Provider
Application Assembler
Deployer
Bold: Mandatory elements
Red: Default values
<session>
<description>Session bean description</description>
<display-name>Display name for tools</display-name>
<small-icon>File name of a JPEG/GIF image</small-icon>
<large-icon>File name of a JPEG/GIF image</large-icon>
<ejb-name>SomeSessionBean</ejb-name>
<home>com.company.SessionBeanRemoteHome</home>
<remote>com.company.SessionBeanRemote</remote>
<local-home>com.company.SessionBeanLocalHome</local-home>
<local>com.company.SessionBeanLocal</local>
<ejb-class>com.company.SessionBeanEJB</ejb-class>
<session-type>Stateful / Stateless</session-type>
<transaction-type>Container / Bean</transaction-type>
<env-entry> <!--optional-->
...
</env-entry>
<ejb-ref> <!--optional-->
...
</ejb-ref>
<ejb-local-ref> <!--optional-->
...
</ejb-local-ref>
<resource-ref> <!--optional-->
...
</resource-ref>
<resource-env-ref> <!--optional-->
...
</resource-env-ref>
<security-role-ref> <!--optional-->
...
</security-role-ref>
<security-identity> <!--optional-->
...
</security-identity>
</session>
Bean Provider
Application Assembler
Deployer
Bold: Mandatory elements
Red: Default values
<message-driven>
<description>Message-driven bean description</description>
<display-name>Display name for tools</display-name>
<small-icon>File name of a JPEG/GIF image</small-icon>
<large-icon>File name of a JPEG/GIF image</large-icon>
<ejb-name>SomeMDBean</ejb-name>
<ejb-class>com.company.MDBeanEJB</ejb-class>
<transaction-type>Container / Bean</transaction-type>
<message-selector>Some message selector</message-selector>
<acknowledge-mode>Auto-acknowledge / Dups-ok-acknowledge</acknowledge-mode>
<message-driven-destination> <!--optional-->
<destination-type>javax.jms.Queue / javax.jms.Topic</destination-type>
<subscription-durability>Durable / NonDurable</subscription-durability>
</message-driven-destination>
<env-entry> <!--optional-->
...
</env-entry>
<ejb-ref> <!--optional-->
...
</ejb-ref>
<ejb-local-ref> <!--optional-->
...
</ejb-local-ref>
<resource-ref> <!--optional-->
...
</resource-ref>
<resource-env-ref> <!--optional-->
...
</resource-env-ref>
<security-identity> <!--optional-->
<description>MDB Security identity description. Only run-as!!</description>
<run-as>
<description>Run as description</description>
<role-name>Manager</role-name>
</run-as>
</security-identity>
</message-driven>
</enterprise-beans>
Bean Provider
Application Assembler
Deployer
Bold: Mandatory elements
Red: Default values
<relationships> <!--optional-->
<description>Relationships description</description>
<ejb-relation>
<description>EJB Relation description</description>
<ejb-relation-name>Entity1-Entity2</ejb-relation-name>
<ejb-relationship-role>
<description>EJB Relationship role description</description>
<ejb-relationship-role-name>Entity1-has-an-Entity2</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<description>EJB Relationship role source description</description>
<ejb-name>SomeEntityBean</ejb-name>
</relationship-role-source>
<cmr-field> <!-- optional -->
<description>Container-managed relationship field description</description>
<cmr-field-name>cmrField1</cmr-field-name>
<cmr-field-type>java.util.Collection / java.util.Set</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<description>EJB Relationship role description</description>
<ejb-relationship-role-name>Entity2-belongs-to-Entity1</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<cascade-delete /> <!-- only allowed if other role source has multiplicity One!! -->
<relationship-role-source>
<description>EJB Relationship role source description</description>
<ejb-name>SomeOtherEntityBean</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
<ejb-relation>
...
</ejb-relation>
</relationships>
Bean Provider
Application Assembler
Deployer
Bold: Mandatory elements
Red: Default values
<assembly-descriptor> <!--optional-->
<security-role> <!--optional-->
<description>Security role description</description>
<role-name>Administrator</role-name>
</security-role>
<method-permission> <!--optional-->
<role-name>everyone</role-name> OR <unchecked />
<method> <!--Style 1-->
<description>Style 1 Method description</description>
<ejb-name>SomeEntityBean</ejb-name>
<method-intf>Home / Remote / LocalHome / Local</method-intf>
<method-name>*</method-name>
</method>
<method> <!--Style 2-->
<description>Style 2 Method description</description>
<ejb-name>SomeEntityBean</ejb-name>
<method-intf>Home / Remote / LocalHome / Local</method-intf>
<method-name>create</method-name>
</method>
<method> <!--Style 3-->
<description>Style 3 Method description</description>
<ejb-name>SomeEntityBean</ejb-name>
<method-intf>Home / Remote / LocalHome / Local</method-intf>
<method-name>createSomething</method-name>
<method-params> <!--optional-->
<method-param>java.lang.String</method-param>
</method-params>
</method>
</method-permission>
<container-transaction> <!--optional-->
<description>Container transaction description</description>
<method> <!-- Style 1, 2 or 3-->
<ejb-name>SomeEntityBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required/RequiresNew/Mandatory/Never/Supports/NotSupported</trans-attribute>
</container-transaction>
<exclude-list> <!--optional-->
<description>Exclude list description</description>
<method> <!-- Style 1, 2 or 3-->
<ejb-name>SomeEntityBean</ejb-name>
<method-name>method1</method-name>
</method>
</exclude-list>
</assembly-descriptor>
<ejb-client-jar>someOtherClientJarFile.jar</ejb-client-jar> <!-- optional -->
</ejb-jar>
Bean Provider
Application Assembler
Deployer
Bold: Mandatory elements
Red: Default values