lab7the hibernate Web FrameworkWord文档格式.docx
- 文档编号:15339819
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:19
- 大小:171.29KB
lab7the hibernate Web FrameworkWord文档格式.docx
《lab7the hibernate Web FrameworkWord文档格式.docx》由会员分享,可在线阅读,更多相关《lab7the hibernate Web FrameworkWord文档格式.docx(19页珍藏版)》请在冰豆网上搜索。
∙GeneratingHibernateMappingFilesandJavaClasses
∙CreatingtheFilmHelper.javaHelperClass
oCreatingtheClass
oEnumeratingFilmTitlesUsinganHQLQuery
oEnumeratingActors(UsingHQLSubQueries)
oAddingAdditionalHelperMethods
∙CreatingtheWebPages
oModifyingindex.jsp
oCreatingbrowse.jsp
∙RunningtheProject
Tofollowthistutorial,youneedthefollowingsoftwareandresources.
SoftwareorResource
VersionRequired
NetBeansIDE
6.1or6.5,Javaversion
JavaDevelopmentKit(JDK)
Version6orversion5
ApacheTomcat
6.0.18
MySQLdatabaseserver
Version5.x
SakilaDatabase
Pluginavailablefromupdatecenter
Note.TheApacheTomcatwebserverisincludedwiththebundleddownloadoftheIDE.Alternatively,youcanusethebundledGlassFishApplicationServer.
CreatingtheDatabase
ThistutorialusesaMySQLdatabasecalledsakila,afreesampleMySQLdatabasethatisavailablefromtheMySQLsite.ThesakiladatabaseisnotincludedwhenyouinstalltheIDEsoyouneedtofirstcreatethedatabasetofollowthistutorial.
TocreatethesakiladatabaseyoucandownloadandinstalltheSakilaSampleDatabasepluginusingthePluginsmanager.AfteryouinstallthepluginthesakiladatabaseisaddedtothelistofdatabasesintheCreateMySQLdatabasedialogbox.
FormoreinformationonconfiguringtheIDEtoworkwithMySQL,seetheConnectingtoaMySQLDatabasetutorial.
1.OpenthePluginsmanagerandinstalltheSakilaSampleDatabaseplugin.
2.Afterinstallingtheplugin,starttheMySQLdatabasebyexpandingtheDatabasesnodeintheServiceswindow,right-clickingtheMySQLServernodeandchoosingStart.
3.Right-clicktheMySQLServernodeandchooseCreateDatabase.
4.SelecttheSakiladatabasefromtheNewDatabaseNamedropdownlistintheCreateMySQLDatabasedialogbox.ClickOK.
WhenyouclickOKaSakilanodeappearsundertheMySQLServernode.
5.Right-clicktheSakilanodeandchooseConnect.
WhenyouclickConnectadatabaseconnectionnodefortheSakiladatabase(jdbc:
mysql:
//localhost:
3306/sakila[usernameonDefault])islistedundertheDatabasesnode.Whenaconnectionisopenyoucanviewthedatainthedatabasebyexpandingtheconnectionnode.
CreatingtheWebApplicationProject
InthisexerciseyouwillcreateawebapplicationprojectandaddtheHibernatelibrariestotheproject.Whenyoucreatetheproject,youwillselectHibernateintheFrameworkspaneloftheNewProjectwizardandspecifythedatabase.
1.ChooseFile>
NewProject(Ctrl-Shift-N).SelectWebApplicationfromtheJavaWebcategoryandclickNext.
2.TypeDVDStorefortheprojectnameandsettheprojectlocation.
3.DeselecttheUseDedicatedFolderoption,ifselected.
Forthistutorialthereislittlereasontocopyprojectlibrariestoadedicatedfolderbecauseyouwillnotneedtosharelibrarieswithotherusers.
ClickNext.
4.SettheservertoApacheTomcat6.0.18andsettheJavaEEVersiontoJavaEE5.ClickNext.
5.SelecttheHibernate3.2.5checkbox.
6.SelectthesakiladatabasefromtheDatabaseConnectiondropdownlist.ClickFinish.
Note:
IfthesakiladatabaseisnotavailableasanoptionintheFrameworkspanelinthewizard,checktoseeiftheconnectionislistedundertheDatabasesnodeintheServiceswindow.Iftheconnectionisnotthere,youneedtocreatethedatabaseconnection.
WhenyouclickFinish,theIDEcreatesthewebapplicationprojectandopensthehibernate.cfg.xmlfileandindex.jspintheeditor.
IfyouexpandtheLibrariesnodeintheProjectswindow,youcanseethattheIDEaddedtheHibernatelibrariestotheproject.
ModifyingtheHibernateConfigurationFile
WhenyoucreateanewprojectthatusestheHibernateframework,theIDEautomaticallycreatesthehibernate.cfg.xmlconfigurationfileattherootofthecontextclasspathoftheapplication(intheFileswindow,WEB-INF/classes).ThefileislocatedundertheConfigurationFilesnodeintheProjectswindow.Theconfigurationfilecontainsinformationaboutthedatabaseconnection,resourcemappings,andotherconnectionproperties.Youcaneditthefileusingthemulti-vieweditor,oredittheXMLdirectlyintheXMLeditor.
Inthisexerciseyouwilleditthedefaultpropertiesspecifiedinhibernate.cfg.xmltoenabledebugloggingforSQLstatementsandtoenableHibernate'
ssessioncontextmanagement.
1.Openhibernate.cfg.xmlintheDesigntab.YoucanopenthefilebyexpandingtheConfigurationFilesnodeintheProjectswindowanddouble-clickinghibernate.cfg.xml.
2.ExpandtheConfigurationPropertiesnodeunderOptionalProperties.
3.ClickAddtoopentheAddHiber
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- lab7the hibernate Web Framework