版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
在Eclipse中使用HibernateWorkingwithHibernateinEclipseEditor'sNote:WithoursurveyresultsshowingahugeinterestinHibernate,wethoughtthiswouldbeagoodweektobringbackthispiece,bytheauthorofO'Reilly'sHibernatebook,onhowtouseHibernatewithEclipse,whichwasalsoatopvote-getterinthepoll.IntroductionIrecentlystartedusingEclipseasmydevelopmentenvironment,inpartbecauseofitssupportforthemanyplatformsonwhichIdevelop,andinpartbecauseEclipseisagreatexampleofthepowerofanopen,extensibleenvironmentinwhichpeopleallaroundtheworldcancontribute.I'mbeginningtoinvestigatetheextensionspeoplehavecomeupwith.Forexample,IusealittleplugincalledXMLBuddytoworkwithXMLfiles,andit'sveryhelpful.SoIbecamecuriousaboutwhetheranyonehadwrittenpluginstoworkwithHibernate,sinceI'vedonesomuchofthatrecentlyinputtingtogethertheDeveloper'sNotebook.Itturnsoutthereareseveralsucheffortsunderway;inthisarticlewewillexploreoneofthem--theHibernateSynchronizer.HibernateSynchronizerOfthepluginsI'vefoundsofar,theHibernateSynchronizerinterestedmemostbecauseitseemstobestsupportthekindofmapping-centricworkflowIadoptedthroughoutmyDeveloper'sNotebook.(Hibernatecanbeusedinmanydifferentways,socheckouttheotherpluginsavailable;thesemaybemorehelpfulifyourenvironmentcallsforanotherapproach.)Infact,theHibernateSynchronizerpluginremovestheneedforyoutothinkaboutupdatingyourJavacodewhenyouchangeyourmappingdocument.InaveryEclipse-likeway,itautomaticallyupdatestheJavacodeasyoueditthemapping.ButitgoesevenfartherthanHibernate'sbuilt-incodegenerationtoolsbycreatingapairofclassesforeachmappedobject.It"owns"abaseclass,whichitrewritesatwillasyouchangethemapping,andgivesyouasubclassthatextendsthisbaseclass,whereyoucanputbusinesslogicandothercode,withoutfearthatitwillevergetchangedoutfromunderyou.AsbefitsanapproachcenteredaroundtheHibernatemappingdocument,HibernateSynchronizerincludesaneweditorcomponentforEclipsethatprovidesintelligentassistanceandcodecompletionforsuchdocuments.AniceDTD-drivenXMLeditor,suchastheaforementionedXMLBuddy,candosomeofthisforyou,butHibernateSynchronizerusesitssemanticunderstandingofthedocumentstogomuchfurther.Italsooffersagraphicalviewofthepropertiesandrelationsinthemapping,"wizard"interfacesforcreatingnewelements,andothersuchniceties.And,asmentioned,initsdefaultconfigurationtheeditorautomaticallyregeneratesthedata-accessclassesasyouedittheirmappingdocuments.ThereareotherpiecestoHibernateSynchronizer,too.ItaddsasectiontoEclipse'sNewmenuthatprovideswizardsforcreatingHibernateconfigurationandmappingfiles,andaddscontextualmenuentriesinthepackageexplorerandinotherappropriateplaces,providingeasyaccesstorelevantHibernateoperations.OK,enoughabstractdescription,timetogetdowntothepracticalstuff!Afterall,youwerealreadyprobablyinterestedinthis,oryouwouldn'thavestartedtoreadthearticle.SohowdoyougetandplaywithHibernateSynchronizer?InstallationHibernateSynchronizerisinstalledusingEclipse'sbuilt-inUpdateManager.ThepluginoffersseparateupdatesitesforusersofEclipse2.1andtheforthcomingEclipse3.BecauseI'musingEclipseformission-criticalwork,I'mstillusingtheproductionrelease,2.1.AsIwritethis,Eclipse3hasenteredits"releasecandidate"phase,andIamverymuchlookingforwardtobeingabletoupgradetoaproductionreleaseofversion3whenIreturnfromJavaOnelaterthissummer.(ThemainreasonImentionthisistoemphasizethatthefollowinginstructionsarewrittenfromanEclipse2perspective;somecommandsandscreensareundoubtedlydifferentinEclipse3,soifyou'reusingit,besuretoapplyyourownjudgmentinfollowingthesesteps!Ifithelps,myimpressionisthatHibernateSynchronizer'sowninstallinstructionsarewrittenforEclipse3.)FireupEclipseandopentheUpdateManagerbychoosingHelp->SoftwareUpdates->UpdateManager.OncetheInstall/Updateperspectiveopensup,right-click(orcontrol-click,ifyou'reusingaone-buttonmouse)intheFeatureUpdatesviewandchooseNew->SiteBookmark.Figure1.AddingtheHibernateSynchronizerpluginsitetotheUpdateManagerIntheresultingdialog,entertheURLfortheversionofthepluginthatyouneed.TheURLtobeentereddependsonyourEclipseversion:Youalsoneedtoassignanameforthenewbookmark."HibernateSynchronizer"makesalotofsense.OnceyouclickFinish,thenewbookmarkwillappearintheFeatureUpdatesview.Toactuallyinstalltheplugin,clickonthedisclosuretriangletotheleftofthebookmark,andagainonthenextonethatappearsinsideofit,untilyoucanseetheiconforthepluginitself.Whenyouclickonthat,thePreviewviewwillupdatetoshowyouaninterfacethatallowsyoutoinstalltheplugin.ClickInstallNowtoactuallyinstallit,andletEclipsewalkyouthroughtheprocess.SeeTrade-Offs,below,forsomediscussionaboutthislicenseagreement.YoumaywishtoreaditcarefullybeforedecidingtouseHibernateSynchronizerinaprojectofyourown.Ithinkit'sprobablyfine,butitisconfusinglybasedontheGPLwithoutactuallybeingopensource.Nowthatthepluginisinstalled,youneedtoquitandrelaunchEclipseforittotakeeffect.ThedialogseemstoimplythatEclipsewillrestartitself,butinmyexperience,clickingYesmerelycausestheenvironmenttoquit,andyouhavetorelaunchitmanually.ThismaybealimitationofEclipse2.1'sMacOSXimplementation;Eclipse3isgoingtobethefirstreleasethatpromises"first-class"supportforOSX.Inanycase,thisisaveryminorissue.IfyouneedtorestartEclipse,dosonow,becauseit'stimetostartconfiguringtheplugintoputitthroughitspaces!ConfigurationOnceEclipsecomesbackup,youcanclosetheInstall/Updateperspective.OpenaJavaprojectthatusesHibernate.Ifyou'vebeengoingthroughtheexamplesintheDeveloper'sNotebook,you'llhaveseveraldirectoriesfromwhichtochoose.I'llbelookingattheexamplesastheyexistinChapter3,whichisthesamplechapteravailableonline.Youcanalsodownloadthesourceforalloftheexamplesfromthebook'ssite.Ifyou'recreatinganewEclipseprojecttoworkwithoneoftheexamplesourcedirectories,justchooseFile->New->Project,specifythatyouwanttocreateaJavaprojectandclickNext,giveitaname("HibernateCh3"inmycase,asshowninFigure11),unchecktheUsedefaultcheckboxsothatyoucantellEclipsewheretofindtheexistingprojectdirectory,andhittheBrowsebuttontolocatewhereitexistsonyourowndrive.Atthispoint,youcanclickFinishtocreatetheproject,butIgenerallyliketoclickNextanddouble-checkthedecisionsEclipseismaking.(Ofcourse,ifitgetsanythingwrong,youcanalwaysgobackandfixtheprojectproperties,butItendtofinditdisconcertingtobegreetedbyatonoferrorsandwarningsimmediatelyifthereisalibrarymissingorsomething.)Inthiscase,mycautionwasunnecessary.Eclipsefiguredoutexactlyhowthedirectorywasstructuredandintendedtobeused,andfoundallofthethird-partylibrariesIhaddownloadedandinstalledinordertoenableHibernateandtheHSQLDBdatabaseenginetorun.(AdetailedwalkthroughofthisprocessisthebulkofChapter1ofmyDeveloper'sNotebook.)ThiskindofsmartadaptabilityisoneofthegreatfeaturesofEclipse.Figure12showsournewprojectopenandreadyforexperimentation.ItalsoshowsthatEclipsedoesn'tliketofitintoawindowsmallenoughforareasonablescreenshot;I'mgoingtohavetoworkwithpartialwindowcapturesfromthispointon.ThenextthingweneedtodoiscreateaHibernateconfigurationfilethatHibernateSynchronizercanuse.Tpertiesfileinthesrcdirectory,whichishowtheexamplesinthebookwork,butHibernateSynchronizeronlyworkswithHibernate'sXML-basedconfigurationapproach.Sowe'pertiesintoanewhibernate.cfg.xmlfile.Onthebrightside,thisgivesusourfirstopportunitytoplaywithafeatureofHibernateSynchronizer,theconfigurationfilewizard.ChooseFile->New->Other,clickthenewlyavailableHibernatecategory,pickHibernateConfigurationFile,andclickNext.Whenthewizardstartsup,thedirectoryitofferstoputthefileintodependsonthefileyou'vecurrentlygotselectedinEclipse.Let'sbesuretoputitatthetop-levelsrcdirectoryalongsidethepropertiesversion,forconsistency.Fillintherestoftheinformationrequestedbythewizardtomatchthepropertiesversionoftheconfiguration,asshowninFigure14.Noticethat,unlikewhenusingAnttocontroltheexecutionofHibernate(whichwastheapproachusedintheDeveloper'sNotebook),wehavenowaytocontrolthecurrentworkingdirectorywhenHibernateisinvoked,soweneedtouseafullyqualifiedpathtothedatabasefileintheURL.Inmycase,thistakesthe(somewhatungainly)valuejdbc:hsqldb:/Users/jim/Documents/Work/OReilly/Hibernate/Examples/ch03/data/music.(IfanyonecantellmehowtogetEclipseorHibernateSynchronizertouseaparticularworkingdirectoryforaproject,I'dcertainlybeinterested.I'mstillabeginnerwhenitcomestoEclipse,soitwouldnotsurprisemeatalltolearnthatthisispossibleandthatIsimplydon'tknowhowtodoit.)FillingintheDriverClassisalittlestrange:YouneedtoclicktheBrowsebutton,andstarttypingthedrivername.Ifyoutype"jdbcD",thewindowwillpresentonlytwochoices,andyoucaneasilyclicktherightone.YoucanclickFinishtocreatetheconfigurationfile.HibernateSynchronizerisnowreadytouse.ItopensthefileitcreatedsoyoucanseethestructureanddetailsofanXMLconfigurationfileforHibernate.Aquickwaytotestthattheconfigurationisworkingistoplaywiththeotherwizardinterface.ChooseFile->New->Other,clickthenewlyavailableHibernatecategory,pickHibernateMappingFile,andclickNext.Whenthewizardcomesup,itshouldbepopulatedwiththesettingsinformationwejustentered,andyoucanclicktheRefreshbuttontomakesureitcancommunicatewiththedatabaseandshowyouthatitfoundaTRACKtable.Thefirsttimeyoudothis,youmighthavetoconfirmthelocationofthe.jarfilecontainingtheHSQLDBdriver,forsomereason,butthatseemstohappenonlyonce.Inanycase,onceyouconfirmthateverythingseemstobeworking,clickCancelratherthanactuallycreatingthemapping,becausewewanttoworkwithourhand-createdmappingfilethatalreadyexists.GeneratingCodeThisisprobablythepartyou'vebeenwaitingfor.Whatcoolstuffcanwedo?Well,rightawaythereisanewcontextualmenuentryavailableforHibernatemappingdocuments.Ifyouright-click(orcontrol-click)onone,yougetanumberofHibernate-relatedchoices(Figure17),includingonetosynchronize.ThisisamanualwaytoaskHibernateSynchronizertogeneratethedataaccessobjectsassociatedwiththemappingdocument.TheAddMappingReferencechoiceisalsouseful:itaddsanentrytothemainHibernateconfigurationfiletellingitaboutthismappingdocument,soyoudon'tneedtoputanythinginyoursourcecodetorequestthatthecorrespondingmappinggetssetup.Fornow,let'slookattheresultofchoosingSynchronizeFiles.Thisiswherethingsstarttogetinteresting.Weendupwithtwonewsub-packages,oneforthe"base"dataaccessobjectsthatHibernateSynchronizer"owns"andcanrewriteatanytime,andoneforourbusinessobjectsthatsubclasstheseDAOs,whichwillnotgetoverwritten,andgiveusanopportunitytoaddbusinesslogictothedataclass.TherearemanymoreclassesgeneratedthiswaythanbyusingthenormalHibernatecodegenerationfacilities,whichhasadvantages,aswellassomepotentialdisadvantages,whichIdiscusslaterintheTrade-Offssection.Notealsothatinthepropertiesconfigurationforyourproject,youcanchoosewhichoftheseclassesgetgeneratedforyou,aswellasthepackagestructureintowhichtheyaregenerated.I'ddemonstratethis,butthecurrentreleaseofthepluginhasabugwhichblocksaccesstothisconfigurationinterfaceonMacOSX.Afixhasbeenmade,butnotyetreleased.BasedontheexamplesontheHibernateSynchronizerpage,Iputtogetherthefollowingclasstotryinsertingsomedataintothemusicdatabaseusingthesenewdataaccessobjects.It'squitesimilartotheversionusingthestandardHibernatecodegenerator(onpages39-40ofHibernate:ADeveloper'sNotebook)andevensimplerbecausetheclassesgeneratedbyHibernateSynchronizercreateandcommitanewtransactionforeachofyourdatabaseoperations,soyoudon'tneedanycodetosetoneupinsimplesituationslikethis.(Therearewaysofdoingsoifyouneedtohaveagroupofoperationsoperateasasingletransaction,ofcourse.)Here'sthecodeforthenewversion:packagecom.oreilly.hh;importjava.sql.Time;importjava.util.Date;importnet.sf.hibernate.HibernateException;importcom.oreilly.hh.dao.TrackDAO;importcom.oreilly.hh.dao._RootDAO;/***TrycreatingsomedatausingtheHibernateSynchronizerapproach.*/publicclassCreateTest2{publicstaticvoidmain(String[]args)throwsHibernateException{//Loadtheconfigurationfile_RootDAO.initialize();//CreatesomesampledataTrackDAOdao=newTrackDAO();Tracktrack=newTrack("RussianTrance","vol2/album610/track02.mp3",Time.valueOf("00:03:30"),newDate(),(short)0);dao.save(track);track=newTrack("VideoKilledtheRadioStar","vol2/album611/track12.mp3",Time.valueOf("00:03:49"),newDate(),(short)0);dao.save(track);//Wedon'tevenneedatrackvariable,ofcourse:dao.save(newTrack("Gravity'sAngel","/vol2/album175/track03.mp3",Time.valueOf("00:06:06"),newDate(),(short)0));}}HavingEclipsearoundwhileIwaswritingthiswasverynice.I'dforgottenhowmuchImissedintelligentcodecompletionwhileIwaswritingtheexamplesforthebook,andthereareseveralotherthingstheJDThelpswithtoo.TorunthissimpleprogramwithinEclipse,weneedtosetupanewRunconfiguration.ChooseRun->Run...withCreateTest2.javaasthecurrentlyactiveeditorfile.ClickonNewandEclipsefiguresoutthatwewanttorunthisclassinourcurrentproject,becausewecreateditwithamain()method.Thedefaultnameitassigns,CreateTest2,isfine.SinceIknewIdidn'tneedtouseJTA,IwonderedwhyHibernatewaseventrying.IopeneduptheHibernateconfigurationfile(Figure16)andlookedforanythingsuspiciousthatHibernateSynchronizerhadputthere.Sureenough,thereweresomelinesthatlookedlikeprimesuspects:<propertyname="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property><propertyname="jta.UserTransaction">java:comp/UserTransaction</property>OnceItriedcommentingtheseoutandrunningagain,thethirdtimewasindeedthecharm.Myruncompletedwithnoerrors,andmydataappearedinthedatabase.Hurrah!Runningthetrustyantdbtarget(explainedinChapter1oftheDeveloper'sNotebook)revealsthedatainallits(admittedlysimple)glory,asshowninFigure20.Ifyou'redoingthisyourself,besuretostartwithanantschematocreatethedatabaseschemaoremptyoutanytestdatathatmaybetherefrompreviousexperimentation.Figure20.ThedatacreatedbyourtestprogramNotethatyoucanrunAnttargetsfromwithinEclipsebyright-clicking(orcontrol-clicking)onthebuild.xmlfilewithinthePackageExplorer,choosingRunAnt,andpickingthetargetusinganEclipsedialog.Prettycool.Gettingdatabackoutusingqueriesisprettystraightforward,althoughthistimeit'salotclosertothesamecodeyou'dusewiththeordinaryHibernate-generateddataaccessclasses.EventhoughHibernateSynchronizergeneratesanumberofhelpermethodsforworkingwithnamedqueries,Idon'tthinkanyofthemisparticularlyuseful,becausetheyallinsistonrunningthequeryandreturningthelistofresults,ratherthangivingyoutheQueryobjecttoworkwithyourself.ThatpreventsyoufromusinganyofQuery'sconvenienttype-safeparametersettingmethods.Becauseofthat,Idecidedtosticktohavingthe_RootDAOobjectgivemeaHibernateSessiontoworkwiththe"oldfashioned"way.Infairness,IthinkIcouldeditthetemplatesusedbyHibernateSynchronizertogenerateanymethodsI'dlike,andwouldalmostcertainlylookintodoingthatifIwasgoingtoundertakeaprojectwithit.Actually,onfurtherreflection,becauseyoucanonlyworkwithaQuerywhileyou'vegotanactiveSession,themethodsofferedbytheDAOsalreadyworkthebestwaytheypossiblycan.You'realwaysgoingtohavetodoyourownsessionmanagementifyouwanttoworkwiththequerythewayIdointhisexample.Youcouldembedthesessionmanagementintothebusinesslogicprovidedin"your"halfoftheDAO,though,whichwouldgiveyouthebestofbothworlds.That'sanotherreasonthesplit-classmodelofferedbyHibernateSynchronizerissouseful.Iexplorethisinsightabitbelow.Anyway,here'sthecodeIfirstcameupwith,morallyquiteequivalenttothatonpages48-49ofthebook:packagecom.oreilly.hh;importjava.sql.Time;importjava.util.ListIterator;importnet.sf.hibernate.HibernateException;importnet.sf.hibernate.Query;importnet.sf.hibernate.Session;importcom.oreilly.hh.dao.TrackDAO;importcom.oreilly.hh.dao._RootDAO;/***UseHibernateSynchronizer'sDAOstorunaquery*/publicclassQueryTest3{publicstaticvoidmain(String[]args)throwsHibernateException{//Loadtheconfigurationfileandgetasession_RootDAO.initialize();Sessionsession=_RootDAO.createSession();try{//PrintthetracksthatwillfitinfiveminutesQueryquery=session.getNamedQuery(TrackDAO.QUERY_COM_OREILLY_HH_TRACKS_NO_LONGER_THAN);query.setTime("length",Time.valueOf("00:05:00"));for(ListIteratoriter=query.list().listIterator();iter.hasNext();){TrackaTrack=(Track)iter.next();System.out.println("Track:\""+aTrack.getTitle()+"\","+aTrack.getPlayTime());}}finally{//Nomatterwhat,closethesessionsession.close();}}}OnenicefeaturethatTrackDAOdoesgiveusisastaticconstantbywhichwecanrequestthenamedquery,eliminatinganychancesofrun-timeerrorsduetotyposinstringliterals.Iappreciatethat!SettingupandexecutingaRunconfigurationforthistestclassproducestheoutputI'dexpect.AsInotedabove,aftergettingthisclassworking,Irealizedtherewasabetterwaytoapproachit,giventhemodelofferedbyHibernateSynchronizer.Here'swhatourTrackDAOobjectwouldlooklikeifwemovedthequeryinsideofit,whichiswhereitreallybelongs,giventhatthenamedqueryisafeatureofthemappingfileassociatedwiththatdataaccessobject:packagecom.oreilly.hh.dao;importjava.sql.Time;importjava.util.List;importnet.sf.hibernate.HibernateException;importnet.sf.hibernate.Query;importnet.sf.hibernate.Session;importcom.oreilly.hh.base.BaseTrackDAO;/***ThisclasshasbeenautomaticallygeneratedbyHibernateSynchronizer.*Formoreinformationordocumentation,visitTheHibernateSynchronizerpage*at://binamics/hibernatesyncorcontactJoeHudsonatjoe@binamics.**ThisistheobjectclassthatrelatestotheTRACKtable.*Anycustomizationsbelonghere.*/publicclassTrackDAOextendsBaseTrackDAO{//ReturnthetracksthatfitwithinaparticularlengthoftimepublicstaticListgetTracksNoLongerThan(Timetime)throwsHibernateException{Sessionsession=_RootDAO.createSession();try{//PrintthetracksthatwillfitinfiveminutesQueryquery=session.getNamedQuery(QUERY_COM_OREILLY_HH_TRACKS_NO_LONGER_THAN);query.setTime("length",time);returnquery.list();}finally{//Nomatterwhat,closethesessionsession.close();}}}Thisisniceandclean,anditsimplifiesthemain()methodinQueryTest3evenmore:publicstaticvoidmain(String[]args)throwsHibernateException{//Loadtheconfigurationfileandgetasession_RootDAO.initialize();//PrintthetracksthatfitinfiveminutesListtracks=TrackDAO.getTracksNoLongerThan(Time.valueOf("00:05:00"));for(ListIteratoriter=tracks.listIterator();iter.hasNext();){TrackaTrack=(Track)iter.next();System.out.println("Track:\""+aTrack.getTitle()+"\","+aTrack.getPlayTime());}}Thisisniceandclean,anditsimplifiesthemain()methodinQueryTest3evenmore:publicstaticvoidmain(String[]args)throwsHibernateException{//Loadtheconfigurationfileandgetasession_RootDAO.initialize();//PrintthetracksthatfitinfiveminutesListtracks=TrackDAO.getTracksNoLongerThan(Time.valueOf("00:05:00"));for(ListIteratoriter=tracks.listIterator();iter.hasNext();){TrackaTrack=(Track)iter.next();System.out.println("Track:\""+aTrack.getTitle()+"\","+aTrack.getPlayTime());}}ClearlythisistheapproachtotakewhenworkingwithnamedqueriesandHibernateSynchronizer.Aquicktestconfirmsthatitproducesthesameoutput,andit'smuchbettercode.WhetherornotyouwanttouseHibernateSynchronizertogenerateitsownstyleofdataaccessobjects,thereisonelastmajorfeaturetoexplore.EditingMappingsOneofthemainattractionsofHibernateSynchronizerisitsspecializededitorformappingdocuments.Thiseditorcanbeconfiguredtoautomaticallyregeneratetheassociateddataobjectswheneveryousavefiles,butthat'sjustafinaltouch;youmightwanttousetheeditorevenifyou'renotusingtheplugin'scodegenerator.Itgivesyousmartcompletionofmappingdocumentelements,andagraphicaloutlineviewinwhichyoucanmanipulatethem,aswell.Thereisatricktogettingtheeditortoworkforyou,though,atleastifyou'restartingfromthedownloadedsourcecodefrommyDeveloper'sNotebook.Inthedownload,themappingdocumentsarenamedwiththeextension".hbm.xml,"andtheeditorisonlyinvokedforfilesendingwith".hbm".Intheory,youcanconfiguretheextensionmappingswithinEclipsesothatbothextensionsusetheplugin'smappingdocumenteditor,butIwasn'tabletogetthattowork,andIsawthatsomeoneelseonthesupportforumhadthesameproblem.So,atleastfornow,yourbestbetmaybetorenamethefiles.(Ifyou'regoingtostickwithAnt-basedstandardcodegeneration,besuretoupdatethecodegentargetinbuild.xmltousethenewextension,too.)AssoonasIrenamedTrack.hbm.xmltoTrack.hbm,itsiconinthePackageExplorerwasupdatedtolookliketheHibernatelogo,andthedefaulteditorbecametheplugin's,asshowninFigure23.Forwhateverreason,theotherHibernateSynchronizeroptions(asshowninFigure17)areavailablewitheitherextension,buttheeditorisavailableonlywiththeshorterversion.Theeditorhascontext-sensitivecompletionsupportforalloftheelementsyou'readdingwithinthemappingdocument.Figure24showsacoupleofexamples,butnoscreenshotscanreallycapturethedepthandusefulnessofafeaturelikethis;I'dverymuchencourageyoutoinstallthepluginandplaywithityourselfforawhile.Youwillquicklyseehowhelpfulitcanbeinworkingwithmappingdocuments.Theoutlineview,showninFigure26,givesyouagraphicalviewofthehierarchyofclasses,theirmappedelements,namedqueries,andthelikethatarepresentinyourmappingdocument,aswellasgivingyouamenuofferingafewwizardstohelpyoucreatenewones.ThecontextualmenuwithintheeditoritselfalsooffersaFormatSourceCodeoptionyoucanusetocleanupandre-flowthedocument.Therearealreadymanyneatandusefulfeaturesinthiseditor,andit'llbeinterestingtoseehowitgrowsinthefuture.Myonlycomplaint(andaminoroneatthat)isthatthiseditorusesaverydifferentapproachtohelpingyoumanagequotationmarkswhenyoucompleteXMLattributesthantheJDTdoesinJavacode.Switchingbackandforthbetweenthemcanbesomewhatdisorienting.(ThewaytheJDTworkstakesalittlegettingusedtoitself,butonceyoustarttrustingit,it'salmostmagical.)Despitemyfirstimpressionthateverythingflowedfromthemappingdocument,HibernateSynchronizerdoesn'tcurrentlyofferanysupportforcreatingorupdatingadatabaseschemafromyourmappingdocuments.Therehasalreadybeenarequestpostedtothesupportforumaboutthis,anditwouldn'tsurprisemeifwesawthesefeaturesinthefuture;supportshouldn'tbetoodifficult.Fornow,you'llhavetostickwithanapproachliketheAnt-drivenoneinHibernate:ADeveloper'sNotebookifyou'redevelopingyourdatabasefromyourmappings.Alternately,theHibernatorplugindescribedbelowdoessupportschemaupdatesfromwithinEclipse.Imayhavetoinvestigatewhetherit'spossibletohavebothofthesepluginsinstalledatthesametime.Well,Icertainlyhopethiswhirlwindtourhasgivenyouansenseofthecapabilitiesofferedbytheplugin.Ihaven'tcoveredallofthem,byanymeans,sododownloaditandexploreonyourownifanythinghasintriguedyou.Trade-OffsClearlyyoucandosomeneatthingswithHibernateSynchronizer.WillIbeusingitformyownHibernateprojects?Therearesomeplusesandminusestothatidea,andIprobablywon'tdecideuntilIgettothepointofactuallyadoptingHibernateinplaceofourhomebrew(andverysimplistic)lightweightO/Rtoolatwork.Thatisgoingtobeasignificantenoughchangethatweareputtingitoffuntilwet
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论