EnterpriseJavaBeans,3.0
ByBillBurke,RichardMonson-Haefel
...............................................
Publisher:O'Reilly
PubDate:May16,2006
PrintISBN-10:0-596-00978-X
Pages:760
TableofContents|Index
EnterpriseJavaBeans,3.0
ByBillBurke,RichardMonson-Haefel
...............................................
Publisher:O'Reilly
PubDate:May16,2006
PrintISBN-10:0-596-00978-X
Pages:760
TableofContents|Index
Copyright
Dedication
Foreword
Preface
PartPARTI:TheEJB3.0Standard
Chapter1.Introduction
Section1.1.Server-SideComponents
Section1.2.PersistenceandEntityBeans
Section1.3.AsynchronousMessaging
Section1.4.WebServices
Section1.5.TitanCruises:AnImaginaryBusiness
Section1.6.What'sNext?
Chapter2.ArchitecturalOverview
Section2.1.TheEntityBean
Section2.2.TheEnterpriseBeanComponent
Section2.3.UsingEnterpriseandEntityBeans
Section2.4.TheBean-ContainerContract
Section2.5.Summary
Chapter3.ResourceManagementandPrimaryServices
Section3.1.ResourceManagement
Section3.2.PrimaryServices
Section3.3.What'sNext?
Chapter4.DevelopingYourFirstBeans
Section4.1.DevelopinganEntityBean
Section4.2.DevelopingaSessionBean
Chapter5.Persistence:EntityManager
Section5.1.EntitiesArePOJOs
Section5.2.ManagedVersusUnmanagedEntities
Section5.3.PackagingaPersistenceUnit
Section5.4.ObtaininganEntityManager
Section5.5.InteractingwithanEntityManager
Section5.6.ResourceLocalTransactions
Chapter6.MappingPersistentObjects
Section6.1.TheProgrammingModel
Section6.2.BasicRelationalMapping
Section6.3.PrimaryKeys
Section6.4.PropertyMappings
Section6.5.MultitableMappingswith@SecondaryTable
Section6.6.@EmbeddedObjects
Chapter7.EntityRelationships
Section7.1.TheSevenRelationshipTypes
Section7.2.MappingCollection-BasedRelationships
Section7.3.DetachedEntitiesandFetchType
Section7.4.Cascading
Chapter8.EntityInheritance
Section8.1.SingleTableperClassHierarchy
Section8.2.TableperConcreteClass
Section8.3.TableperSubclass
Section8.4.MixingStrategies
Section8.5.NonentityBaseClasses
Chapter9.QueriesandEJBQL
Section9.1.QueryAPI
Section9.2.EJBQL
Section9.3.NativeQueries
Section9.4.NamedQueries
Chapter10.EntityCallbacksandListeners
Section10.1.CallbackEvents
Section10.2.CallbacksonEntityClasses
Section10.3.EntityListeners
Chapter11.SessionBeans
Section11.1.TheStatelessSessionBean
Section11.2.SessionContext
Section11.3.TheLifeCycleofaStatelessSessionBean
Section11.4.TheStatefulSessionBean
Section11.5.TheLifeCycleofaStatefulSessionBean
Section11.6.StatefulSessionBeansandExtendedPersistenceContexts
Section11.7.NestedStatefulSessionBeans
Chapter12.Message-DrivenBeans
Section12.1.JMSandMessage-DrivenBeans
Section12.2.JMS-BasedMessage-DrivenBeans
Section12.3.TheLifeCycleofaMessage-DrivenBean
Section12.4.Connector-BasedMessage-DrivenBeans
Section12.5.MessageLinking
Chapter13.TimerService
Section13.1.Titan'sMaintenanceTimer
Section13.2.TimerServiceAPI
Section13.3.Transactions
Section13.4.StatelessSessionBeanTimers
Section13.5.Message-DrivenBeanTimers
Section13.6.FinalWords
Chapter14.TheJNDIENCandInjection
Section14.1.TheJNDIENC
Section14.2.ReferenceandInjectionTypes
Chapter15.Interceptors
Section15.1.InterceptingMethods
Section15.2.InterceptorsandInjection
Section15.3.InterceptingLifeCycleEvents
Section15.4.ExceptionHandling
Section15.5.InterceptorLifeCycle
Section15.6.BeanClass@AroundInvokeMethods
Section15.7.FutureInterceptorImprovements
Chapter16.Transactions
Section16.1.ACIDTransactions
Section16.2.DeclarativeTransactionManagement
Section16.3.IsolationandDatabaseLocking
Section16.4.NontransactionalEJBs
Section16.5.ExplicitTransactionManagement
Section16.6.ExceptionsandTransactions
Section16.7.TransactionalStatefulSessionBeans
Section16.8.ConversationalPersistenceContexts
Chapter17.Security
Section17.1.AuthenticationandIdentity
Section17.2.Authorization
Section17.3.TheRunAsSecurityIdentity
Section17.4.ProgrammaticSecurity
Chapter18.EJB3.0:WebServicesStandards
Section18.1.WebServicesOverview
Section18.2.XMLSchemaandXMLNamespaces
Section18.3.SOAP1.1
Section18.4.WSDL1.1
Section18.5.UDDI2.0
Section18.6.FromStandardstoImplementation
Chapter19.EJB3.0andWebServices
Section19.1.AccessingWebServiceswithJAX-RPC
Section19.2.DefiningaWebServicewithJAX-RPC
Section19.3.UsingJAX-WS
Section19.4.OtherAnnotationsandAPIs
Chapter20.JavaEE
Section20.1.Servlets
Section20.2.JavaServerPages
Section20.3.WebComponentsandEJB
Section20.4.FillingintheGaps
Section20.5.FittingthePiecesTogether
Chapter21.EJBDesignintheRealWorld
Section21.1.Predesign:ContainersandDatabases
Section21.2.Design
Section21.3.ShouldYouUseEJBs?
Section21.4.WrappingUp
PartPARTII:TheJBossWorkbook
Introduction
Section22.1.ContentsoftheJBossWorkbook
ChapterWORKBOOK1.JBossInstallationandConfiguration
Section23.1.AboutJBoss
Section23.2.InstallingtheJBossApplicationServer
Section23.3.AQuickLookatJBossInternals
Section23.4.ExerciseCodeSetupandConfiguration
ChapterWORKBOOK2.ExercisesforChapter4
Section24.1.Exercise4.1:YourFirstBeanswithJBoss
Section24.2.Exercise4.2:JNDIBindingwithAnnotations
Section24.3.Exercise4.3:JNDIBindingwithXML
ChapterWORKBOOK3.ExercisesforChapter5
Section25.1.Exercise5.1:InteractingwithEntityManager
Section25.2.Exercise5.2:StandalonePersistence
ChapterWORKBOOK4.ExercisesforChapter6
Section26.1.Exercise6.1:BasicPropertyMappings
Section26.2.Exercise6.2:@IdClass
Section26.3.Exercise6.3:@EmbeddedId
Section26.4.Exercise6.4:MultitableMappings
Section26.5.Exercise6.5:EmbeddableClasses
ChapterWORKBOOK5.ExercisesforChapter7
Section27.1.Exercise7.1:Cascading
Section27.2.Exercise7.2:InverseRelationships
Section27.3.Exercise7.3:LazyInitialization
ChapterWORKBOOK6.ExercisesforChapter8
Section28.1.Exercise8.1:SingleTableperHierarchy
Section28.2.Exercise8.2:SingleTableperHierarchy
Section28.3.Exercise8.3:JOINEDInheritanceStrategy
ChapterWORKBOOK7.ExercisesforChapter9
Section29.1.Exercise9.1:QueryandEJBQLBasics
ChapterWORKBOOK8.ExercisesforChapter10
Section30.1.Exercise10.1:EntityCallbacks
Section30.2.Exercise10.2:EntityListeners
ChapterWORKBOOK9.ExercisesforChapter11
Section31.1.Exercise11.1:StatelessSessionBean
Section31.2.Exercise11.2:XMLOverride
Section31.3.Exercise11.3:AnnotationlessStatelessSessionBean
Section31.4.Exercise11.4:StatefulSessionBean
Section31.5.Exercise11.5:AnnotationlessStatefulSessionBean
ChapterWORKBOOK10.ExercisesforChapter12
Section32.1.Exercise12.1:TheMessage-DrivenBean
ChapterWORKBOOK11.ExercisesforChapter13
Section33.1.Exercise13.1:EJBTimerService
ChapterWORKBOOK12.ExercisesforChapter15
Section34.1.Exercise15.1:EJBInterceptors
Section34.2.Exercise15.2:InterceptingEJBCallbacks
ChapterWORKBOOK13.ExercisesforChapter16
Section35.1.Exercise16.1:ConversationalPersistenceContexts
ChapterWORKBOOK14.ExercisesforChapter17
Section36.1.Exercise17.1:Security
Section36.2.Exercise17.2:SecuringThroughXML
ChapterWORKBOOK15.ExercisesforChapter19
Section37.1.Exercise19.1:ExposingaStatelessBean
Section37.2.Exercise19.2:Usinga.NETClient
PartPARTIII:Appendix
JBossDatabaseConfiguration
SectionA.1.SetUptheDatabase
SectionA.2.Examinethepersistence.xmlFile
SectionA.3.StartUpJBoss
SectionA.4.BuildandDeploytheExamplePrograms
SectionA.5.ExamineandRuntheClientApplications
AbouttheAuthors
Colophon
Index
EnterpriseJavaBeans™3.0,FifthEdition
byBillBurkeandRichardMonson-Haefel
Copyright©2006,2004,2001,2000,1999O'ReillyMedia,Inc.
Allrightsreserved.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reillybooksmaybepurchasedforeducational,business,or
salespromotionaluse.Onlineeditionsarealsoavailablefor
mosttitles(safari.oreilly.com).Formoreinformation,contact
ourcorporate/institutionalsalesdepartment:(800)998-9938or
Editor:
MikeLoukides
ProductionEditor:
ColleenGorman
Copyeditor:
AudreyDoyle
Proofreaders:
MattHutchinsonandRachelMonaghan
Indexer:
JulieHawks
CoverDesigner:
HannaDyer
InteriorDesigner:
DavidFutato
Illustrators:
RobertRomanoandJessamynRead
PrintingHistory:
June1999:
FirstEdition.
March2000:
SecondEdition.
September2001:
ThirdEdition.
June2004:
FourthEdition.
May2006:
FifthEdition.
NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
EnterpriseJavaBeans™,FifthEdition,theimageofawallaby
andjoey,andrelatedtradedressaretrademarksofO'Reilly
Media,Inc.
Java™andallJava-basedtrademarksandlogosaretrademarks
orregisteredtrademarksofSunMicrosystems,Inc.,inthe
UnitedStatesandothercountries.O'ReillyMedia,Inc.is
independentofSunMicrosystems.Microsoft,Windows,
WindowsNT,andtheWindowslogoaretrademarksor
registeredtrademarksofMicrosoftCorporationintheUnited
Statesandothercountries.JBossisfullyownedandoperated
byJBoss,Inc.intheUnitedStatesandothercountries.
Manyofthedesignationsusedbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorsassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.
ISBN:0-596-00978-X
[M]
Dedication
Formygirls:Monica,Molly,Abby,andWinnie
BillBurke
Formywifeandbestfriend,Hollie
RichardMonson-Haefel
Foreword
EnterpriseJavaBeans™isthecorecomponenttechnologyofthe
JavaEnterpriseEditionplatform.Itisanenterprise
infrastructuredesignedtoprovidedeveloperswiththe
automaticmanagementofmanyoftheservicesessentialto
enterpriseapplications.TheEJBcontainertheimmediate
environmentofenterprisebeancomponentsandtheproviderof
managedservicestothemisatthecenterofthisarchitecture.
However,tousethismanagedenvironmentinearlierversions
ofEJB,developershadtowritetoAPIsthatfocusedmoreon
theEJBcontainer'srequirementsthanonthebusinesslogicof
enterpriseapplications.Consequently,EJBdevelopmentwas
unnecessarilycomplex.Forexample:
ImplementationofvariousEJBinterfacesledtoalotof
boilerplatecodeformethodsthatwererequiredbythe
interface,butnotneededbytheapplication.
AnXMLdeploymentdescriptorwasrequiredtointegratethe
applicationwithitsenvironmentandwithcontainer
services.Accesstothecomponents'environmentwas
clumsyandnonintuitive.
Thedesignofcontainer-managedpersistencemadedomain
objectmodelingunnecessarilycomplexandheavyweight.
Whilecontainer-managedpersistencewasoriginally
conceivedasanease-of-usefacility,inpractice,itwas
awkwardandlimiting.
ThepurposeoftheEJB3.0releasewastorefocusEJBon
simplifyingthedeveloper'stasksandtofixalloftheseproblems,
andmore.
Oneofthefirststepsinthisprocesswasevaluatingthesources
ofcomplexityintheearlierEJBreleases.Thisinvolved
examiningcriticismsofEJB;understandingwhichEJBdesign
patternswerereallyantipatterns;identifyingAPIsthatwere
clumsytouse,werenonintuitivetonewcomerstothe
technology,orcouldbedispensedwithentirely;andrecognizing
otheraspectsofthetechnologythatwereobstaclestoeaseof
use.
Thepreliminarylistofwhatneededtobefixedtogetherwitha
proposalforhowthetaskcouldbeapproachedformedthebasis
ofJSR220,theJavaCommunityProcessspecificationrequest
withwhichIlaunchedEJB3.0.Startingwiththeinitiallistofthe
APIsthatneededimprovement,theEJB3.0ExpertGroup
undertooktheprocessofbrainstormingonbetter,simpler
constructs.BillBurke,thechiefarchitectoftheJBoss
applicationserverandauthorofthisbook,wasoneofthekey
participantsinthiseffort.
TheExpertGroup'sworkhasresultedinamajorsimplification
andimprovement.AllofthekeyEJBAPIsareeasiertouse,and
theconfiguration-by-exceptionapproachofEJB3.0allows
developerstorelyonexpecteddefaultbehaviors.TheXML
deploymentdescriptorhasbecomeunnecessary,exceptfor
addressingmoreadvancedcases.
TheJavalanguagemetadatafacility,newlyaddedtoJavaSE,
aidedusinmakingthesesimplifications.EJB3.0usesmetadata
annotationstoexpresswithinJavacodethedependenciesof
EJBcomponentsuponcontainerservices,andthustoavoidthe
needtoprovideadeploymentdescriptor.Further,EJB3.0
providesdefaultvaluesformetadatasothatingeneral,this
metadatacanbesparse.
Byusingmetadataannotationstodesignateenvironment
dependenciesandlifecyclecallbacks,EJB3.0hasalsobeen
abletoeliminatetherequirementforthebeanclassto
implementtotheEnterpriseBeaninterfaces.Abeanclasscan
nowselectivelyspecifywhatitneeds,andcanimplementonly
neededmethodsratherthanunnecessaryboilerplatecode.
WewereabletoeliminatetheearlierEJBHomefactorypatterns
aswellbyrequiringsmarterinterpositioningonthepartofthe
container(transparentlytotheapplication)increating
referencestocomponentsandtheirinstancesatthetimeof
lookuporinjection.Sessionbeanscannowbeprogrammedas
ordinaryJavaclasseswithordinarybusinessinterfaces,rather
thanasheavyweightcomponents.
Theseandotherchangeshavegreatlysimplifiedthedeveloper
view.Further,theyleavetheunderlyingEJBarchitecture
fundamentallyunchanged,providingamigrationpathtoEJB
3.0.
Thesimplificationofcontainer-managedpersistenceprovideda
greaterchallenge.Webegantheeffortherewiththesame
stepsasthesimplificationofsessionbeansandmessage-driven
beans:eliminationofunneededinterfaces,useofannotations
forconfigurationinformation,andsoon.Itsoonbecameclear,
however,thatEJBpersistenceneededamoreradical
transformation.Further,thesuccessoflighter-weight
object/relationalmappingtechnologiessuchasHibernategave
clearguidancetothedirectionthatthistransformationshould
take.
Asdescribedinthisbook,theresultingJavaPersistenceAPI
replacescontainer-managedpersistencewithalighter-weight,
PlainOldJavaObject(POJO)persistencelayer.Thislayer
providesextensivesupportfordomainobjectmodeling,
includinginheritanceandpolymorphism;numerous
enhancementstotheEJBQLquerylanguagetoproviderich
querycapabilities;andaspecificationforportable
object/relationalmappingthroughuseofannotationsoranXML
descriptor.Persistententitiesarenowinstancesofordinary(but
managed)Javaclasses.Assuch,theycanbecreatedwithnew
andpassedtootherapplicationtiersasordinaryJavaobjects.
ThemanagedpersistencecontextsprovidedbytheJava
PersistenceAPIprovideparticularleveragewithinEJB3.0
environments,andenabletheeasymodelingofextendedclient
"conversations."
Becauseofthescopeofthiswork,EJB3.0hasgreatlysimplified
enterpriseapplicationdevelopment,andmanyofthefeaturesit
hasintroducedhavebeenincorporatedelsewhereintheJavaEE
platform.Beyondthis,theJavaPersistenceAPIhasbeen
expandedtosupportuse"outsidethecontainer"inJavaSE
environments.
BillBurke'scontributionstoEJB3.0andtheJavaPersistence
APIhavebeennumerousandfarreaching.Aschiefarchitectfor
theJBossapplicationserver,hebroughttotheEJB3.0Expert
Groupkeyinsightsoncontainerinnovations,extensive
experiencewiththeHibernateobject/relationalpersistence
technology,andabroadperspectiveontheneedsofdevelopers
andtheiruseoftheEJBtechnologyinreal-worldapplications.
InthisneweditionofEnterpriseJavaBeans,basedonthe
earlierworkbyRichardMonson-Haefel,BillBurkesharesthese
insightstogetherwithhisin-depthperspectiveonhowthese
new,simplifiedEJB3.0APIstransformtheenterpriseJava
landscapeforapplicationdevelopers.
LindaDeMichiel
EJB3.0ArchitectandSpecificationLead
SunMicrosystems
SantaClara,California
Preface
Author'sNote
Inthespringof2000,IleftmyCORBAdevelopmentjobatIona
andwenttoasmallstartupthatwasbuildingane-marketing
portal.ComingfromaCORBAbackgroundtoanEnterprise
JavaBeans™projectwasabitalientome.Irememberthinking,
"Whydoestheserversideneedacomponentmodel?"Iquickly
learnedthatdeclarativetransaction,security,andpersistence
metadataplayedacrucialroleindevelopingbusiness
applications.
Likemanystartupsatthattime,weranintofundingproblems
attheendof2000.Wewereabouttogointobetawithourfirst
customerswhenourproblemswerecompoundedwhenour
applicationservervendorrevokedourdemolicenseand
demandedpayment.Wehadtofindafreesolutionfast,and
thatwaswhenIstumbledintotheopensourceapplication
server,JBoss.
Itdidn'ttakeverylongtoconverttoJBoss,butIfoundthat
JBoss2.0wasabitrawinsomeareas.Ihadanextensive
backgroundinwritingmiddlewareunderthetutelageofSteve
VinoskiatIona,soitwasn'ttoodifficulttojumpintothe
codebase.Iimmediatelybeganfixingbugshereandthere,
submittingpatchestotheJBossmaillist.Afterafewmonthsof
contributing,Ireceivedastrangeemail:
whatdoyoudoinreallife
TheemailwasfromJBoss'sfounder,MarcFleury.Letmetell
you,JBosswasthefirstopensourceprojectIhadever
contributedto,andreceivinganemailfromthefounderhimself
wasalmostlikereceivingamessagefromGod.OK,maybeI'm
exaggeratingabithere.Itwasmorelikereceivingacoded
messagefromMorpheusinthemovieTheMatrix.Iresponded
toMarc'semail,sayingIworkedforastrugglingstartupand
thatIhadwrittenmiddlewareatmypreviousjobatIona.Igot
aone-sentenceresponsefromMarc:
doyouwanttotaketheredpill
Iwashooked.Irepliedyes,andmyjourneydowntherabbit
holebegan.IbecameaCVScommitterandfirstworkedon
entitybeansynchronization.Laterthatyear,IhelpedSacha
LaboureyonJBoss'sfirstclusteringimplementation.Therestis
history.
Backin2002,RichardMonson-Haefel,theoriginalauthorofthe
EJBbookseries,contactedMarcaboutcontributingaJBoss
workbook.Marcwasn'tinterested,soheintroducedRichardto
SachaLaboureyandme,andwewrotetheworkbookthat
O'Reillypublishedwithitsbook,EnterpriseJavaBeans,Fourth
Edition.WhenRichardretiredfromwritinglastyear,Iguessmy
workwasgoodenoughthatO'Reillyofferedmetheopportunity
toupdatetheseriestothelatestEJB3.0specification.
WhoShouldReadThisBook
Thisbookexplainsanddemonstratesthefundamentalsofthe
EJB3.0andJavaPersistenceprogrammingmodels.Although
EJBmakesapplicationdevelopmentmuchsimpler,itisstilla
complextechnologythatrequiresagreatdealoftimeandstudy
tomaster.Thisbookprovidesastraightforward,no-nonsense
explanationoftheunderlyingtechnology,Java™classesand
interfaces,thecomponentmodel,andtheruntimebehaviorof
EJB.Itdoesnotincludematerialonpreviousversionsofthe
specification,however.
Althoughthisbookfocusesonthefundamentals,it'snota
"dummies"book.EJBisanextremelycomplexandambitious
enterprisetechnology.WhileusingEJBmaybefairlysimple,the
amountofworkrequiredtounderstandandmasterEJBis
significant.Beforereadingthisbook,youshouldbefluentinthe
Javalanguageandhavesomepracticalexperiencedeveloping
businesssolutions.Experiencewithdistributedobjectsystems
isnotamust,butyouwillneedsomeexperiencewithJDBC(or
atleastanunderstandingofthebasics)tofollowtheexamples
inthisbook.IfyouareunfamiliarwiththeJavalanguage,I
recommendLearningJava;thisbookwasformerlyExploring
Java(bothfromO'Reilly).IfyouareunfamiliarwithJDBC,I
recommendDatabaseProgrammingwithJDBCandJava
(O'Reilly).Ifyouneedastrongerbackgroundindistributed
computing,IrecommendJavaDistributedComputing(O'Reilly).
HowThisBookIsOrganized
Thisbookisorganizedintotwoparts:thetechnicalmanuscript,
followedbytheJBossworkbook.Thetechnicalmanuscript
explainswhatEJBis,howitworks,andwhentouseit.The
JBossworkbookprovidesstep-by-stepinstructionsforinstalling,
configuring,andrunningtheexamplesfromthemanuscripton
theJBoss4.0ApplicationServer.
PartI:TheEJB3.0Standard
Part1wasadaptedfromRichardMonson-Haefel'sfourthedition
ofthisbookbyyourstruly,BillBurke.LindaDeMichiel,theEJB
3.0specificationlead,wrotetheforewordtothisbook.JasonT.
GreeneadaptedChapters18and19.Hereisasummaryofthe
contentofthetechnicalmanuscriptchapters:
Chapter1,Introduction
Thischapterdefinescomponenttransactionmonitorsand
explainshowtheyformtheunderlyingtechnologyofthe
EJBcomponentmodel.
Chapter2,ArchitecturalOverview
ThischapterdefinesthearchitectureoftheEJBcomponent
modelandexaminesthedifferencesbetweenthethree
basictypesofenterprisebeans:entitybeans,session
beans,andmessage-drivenbeans.
Chapter3,ResourceManagementandPrimaryServices
ThischapterexplainshowtheEJB-compliantserver
managesanenterprisebeanatruntime.
Chapter4,DevelopingYourFirstBeans
Thischapterwalksyouthroughthedevelopmentofsome
simpleenterpriseandentitybeans.
Chapter5,Persistence:EntityManager
Thischapterexplainshowentitybeansinteractwiththe
newentitymanagerservice.
Chapter6,MappingPersistentObjects
Thischapterdefinesthebasicrelationaldatabasemapping
providedbytheJavaPersistencespecification.
Chapter7,EntityRelationships
ThischapterpicksupwhereChapter6leftoff,expanding
yourunderstandingofpersistenceandcomplexbean-tobeanrelationships.
Chapter8,EntityInheritance
Thischapterdiscussesentitybeaninheritanceandhowan
objecthierarchycanbemappedtoarelationaldatabase.
Chapter9,QueriesandEJBQL
ThischapteraddressestheEnterpriseJavaBeansQuery
Language(EJBQL),whichisusedtoqueryentitybeansand
tolocatespecificentitybeansinJavaPersistence.
Chapter10,EntityCallbacksandListeners
Thischaptercoversthelifecycleofanentitybeanandhow
youcanwriteclassesthatcaninterceptentitylifecycle
events.
Chapter11,SessionBeans
Thischaptershowshowtodevelopstatelessandstateful
sessionbeans.
Chapter12,Message-DrivenBeans
Thischaptershowshowtodevelopmessage-drivenbeans.
Chapter13,TimerService
ThischaptershowshowtousetheTimerServiceinEJB3.0.
Chapter14,TheJNDIENCandInjection
ThischapterexplainstheJNDIENCaswellasthenew
injectionannotationsandtheirXMLequivalents.
Chapter15,Interceptors
ThischapterdiscussesEJBinterceptorsandhowyoucan
usethemtoextendthebehaviorofyourEJBcontainer.
Chapter16,Transactions
Thischapterprovidesanin-depthexplanationof
transactionsanddescribesthetransactionalmodeldefined
byEJB.
Chapter17,Security
ThischapterwalksyouthroughthebasicsofEJBsecurity.
Chapter18,EJB3.0:WebServicesStandards
ThischapterexplainstheXML,SOAP,WSLD,andUDDIweb
servicesstandards.
Chapter19,EJB3.0andWebServices
ThischapterdiscusseshowtheJAX-RPCAPIsupportsweb
servicesinEJB.
Chapter20,JavaEE
ThischapterprovidesanoverviewofJavaEE5andexplains
howEJB3.0fitsintothisnewplatform.
Chapter21,EJBDesignintheRealWorld
Thischapterprovidessomebasicdesignstrategiesthatcan
simplifyyourEJBdevelopmenteffortsandmakeyourEJB
systemmoreefficient.
PartII:TheJBossWorkbook
TheJBossworkbookshowshowtoexecuteexamplesfrom
thosechaptersinthebookthatincludeatleastonesignificant
example.You'llwanttoreadtheintroductiontotheworkbook
tosetupJBossandconfigureitfortheexamples.Afterthat,
justgototheworkbookchapterthatmatchesthechapter
you'rereading.Forexample,ifyouarereadingChapter6on
mappingpersistentobjects,usethe"ExercisesforChapter6"
chapteroftheworkbooktodevelopandruntheexampleson
JBoss.
SoftwareandVersions
ThisbookcoversEJB3.0andJavaPersistence1.0.ItusesJava
languagefeaturesfromtheJavaSE5platform,includingJDBC.
BecausethefocusofthisbookisondevelopingvendorindependentEJBcomponentsandsolutions,Ihavestayedaway
fromproprietaryextensionsandvendor-dependentidioms.You
canuseanyEJB-compliantserverwiththisbook,butyou
shouldbefamiliarwithyourserver'sspecificinstallation,
deployment,andruntime-managementprocedurestoworkwith
theexamples.AworkbookfortheJBossApplicationServeris
includedattheendofthisbooktohelpyougetstarted.
ConventionsUsedinThisBook
Thefollowingtypographicalconventionsareusedinthisbook:
Italic
Usedforfilenamesandpathnames,hostnames,domain
names,URLs,andemailaddresses.Italicisalsousedfor
newtermswheretheyaredefined.
Constantwidth
Usedforcodeexamplesandfragments,XMLelementsand
tags,andSQLcommands,tablenames,andcolumnnames.
Constantwidthisalsousedforclass,variable,andmethod
namesandforJavakeywordsusedwithinthetext.
Constantwidthbold
Usedforemphasisinsomecodeexamples.
Constantwidthitalic
Usedtoindicatetextthatisreplaceable.Forexample,in
BeanNamePK,youwouldreplaceBeanNamewithaspecificbean
name.
Indicatesatip,suggestion,orgeneralnote.
Indicatesawarningorcaution.
AnEnterpriseJavaBeanconsistsofmanyparts;it'snotasingle
object,butacollectionofobjectsandinterfaces.Torefertoan
enterprisebeanasawhole,weuseitsbusinessnameinroman
type,followedbytheacronymEJB.Forexample,wewillrefer
totheTravelAgentEJBwhenwewanttotalkaboutthe
enterprisebeaningeneralandtheCustomerentitywhenwe
wanttotalkaboutentitybeans.Ifweputthenameina
constant-widthfont,wearereferringexplicitlytothebean's
interfaceorclass;thus,TRavelAgentRemoteistheremoteinterface
thatdefinesthebusinessmethodsoftheTravelAgentEJB.
UsingCodeExamples
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdonotneedtocontactusforpermission
unlessyou'rereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesnotrequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesnotrequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdonotrequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"EnterpriseJavaBeans3.0,FifthEdition,byBillBurke
andRichardMonson-Haefel.Copyright2006O'ReillyMedia,
Inc.,0-596-00978-X."
Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseor
thepermissiongivenabove,feelfreetocontactusat
Safari®Enabled
WhenyouseeaSafari®enabledicononthecoverof
yourfavoritetechnologybook,thatmeansthebookisavailable
onlinethroughtheO'ReillyNetworkSafariBookshelf.
Safarioffersasolutionthat'sbetterthane-books.It'savirtual