外文翻译-HIBERNATE技术促进高效的业务应用程序扩展_第1页
外文翻译-HIBERNATE技术促进高效的业务应用程序扩展_第2页
外文翻译-HIBERNATE技术促进高效的业务应用程序扩展_第3页
外文翻译-HIBERNATE技术促进高效的业务应用程序扩展_第4页
外文翻译-HIBERNATE技术促进高效的业务应用程序扩展_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

0附录1HIBERNATETECHNOLOGYFORANEFFICIENTBUSINESSAPPLICATIONEXTENSIONAbstract:Thispaperdiscusseshibernatetechnologyasanovelandefficientmeanstoaccesshugedatabasesandalsofocusesonhowtoimplementpersistentfeaturesinobject-orientedsystemthroughit.Itdiscussescurrentlyavailablehibernatemappingframeworkindetail.Hibernateprovidessupportforcollections,objectrelations,aswellascomplexandcompositetypes.Inadditiontopersistingobjects,hibernatealsoprovidesarichquerylanguagetoretrieveobjectsfromthedatabase,alongwithanefficientcachinglayerandJavaManagementExtensions(JMX)support.Hibernateisapowerful,high-performance,feature-richandverypopularORMsolutionforJava.HibernatefacilitatesdevelopmentofpersistentobjectsbasedonthecommonJavaobjectmodeltomirrortheunderlyingdatabasestructure.Thisapproachprogressesthebusinessperformancetosomeextent,advancesdevelopmentefficiencyexceedinglyandobtainspreferableeconomicalefficiencyandpracticability.Inadditionto,itcomparesandanalyzesthedatabaseaccessefficiencyresultedfromtwomechanismsbasedonHibernateandJDBC.Thispaperoffersinsightintohibernatetechnologyitsimplementationandusage.Keywords:Hibernate,HQL,ORM,Database,SQL.INTRODUCTIONAmajorportionofthedevelopmentofanenterpriseapplicationinvolvesthecreationandmaintenanceofthepersistencelayerusedtoaccumulateandretrieveobjectsfromthedatabaseofchoice1.Manyorganizationsresorttocreatehomegrown,oftenbuggy,persistencelayers.Ifchangesaremadetotheunderlyingdatabaseschema,itcanbeexpensivetodisseminatethose1changestotherestoftheapplication.Hibernatestepsintofillthisgap,providinganeasy-to-useandpowerfulobjectrelationalpersistenceframeworkforJavaapplications.Hibernateisanobject-relationalmapping(ORM)libraryfortheJavalanguage,providingaframeworkformappinganobject-orienteddomainmodeltoatraditionalrelationaldatabase.HibernatesolvesObject-Relationalimpedancemismatchproblemsbyreplacingdirectpersistence-relateddatabaseaccesseswithhigh-levelobjecthandlingfunctions.ORMisapieceofsoftwareproductfortherepresentationandtranslationofdatabetweenthedatabaseandtheobject-orientedprogramminglanguage.HibernateisonesuchORMsolutionanditisanopen-sourceproject.TheHibernate2.1frameworkhaswonaawardin2005.Hibernateprovidessupportforcollectionsandobjectrelations,aswellascompositetypes.Italsoprovidesarichquerylanguagetoretrieveobjectsfromthedatabase,acompetentcachinglayerandhasJavaManagementExtensions(JMX)support.HibernateisreleasedunderthelesserGNUPublicLicense,whichissufficientforuseincommercialaswellasopensourceapplications.Itsupportsnumerousdatabases,includingOracleandDB2,alsopopularopensourcedatabasessuchasPostgreSQLandMySQL.WorkingofHibernateRatherthanutilizingbytecodeprocessingorcodegeneration,hibernateusesruntimereflectiontodeterminethepersistentpropertiesofaclass.Theobjectstobepersistedaredefinedinamappingdocument,whichservestodescribethepersistentfieldsandassociations,aswellasanysubclassesorproxiesofthepersistentobject.Themappingdocumentsarecompiledatapplicationstartuptimeandsupplytheframeworkwithnecessaryinformationforaclass2.Inadditiontoit,theyareusedinsupportoperations,suchasgeneratingthedatabaseschemaorcreatingstubandJavasourcefiles.ASessionFactoryiscreatedfromthecompiledcollectionofmappingdocuments6.TheSessionFactoryprovidesthemechanismformanagingpersistentclassesandtheSessioninterface.TheSessionclassprovidestheinterfacebetweenthepersistent2datastoreandtheapplication.TheSessioninterfacewrapsaJDBCconnection,whichcanbeuser-managedorcontrolledbyhibernate,andisonlyintendedtobeusedbyasingleapplicationthread,thenclosedanddiscarded.HibernateArchitectureThefollowingFigure1andFigure2describesthehighlevelarchitectureofhibernatei.e.theyshowhowhibernateusesthedatabaseandconfigurationdatatoprovidepersistenceservices(andpersistentobjects)toanapplication.TouseHibernate,itrequirescreatingJavaclassesthatrepresentthetableinthedatabaseandthenmaptheinstancevariableintheclasswiththecolumnsinthedatabase.Then,Hibernatecanbeusedtoperformoperationsonthedatabaselikeselect,insert,updateanddeletetherecordsinthetable.Hibernateautomaticallycreatesthequerytoperformtheseoperations.TheFigure1describesthehighlevelarchitectureofhibernate.Figure1.BasicHibernateArchitectureHibernatearchitecturehasfollowingthreemaincomponents.Connectionmanagement:HibernateConnectionmanagementservicegrantefficientmanagementofthedatabaseconnections.Databaseconnectionisthepriciestpartofdatabaseasitrequiresalotofresourcesofopen/closethedatabaseconnection.Transactionmanagement:Transactionmanagementserviceprovidesthecapabilitytotheusertoexecutemorethanonedatabase3statementsatatime.Objectrelationalmapping:Objectrelationalmappingisatechniqueofmappingthedatarepresentationfromanobjectmodeltoarelationaldatamodel.Thispartofthehibernateisusedtoselect,insert,update,viewanddeletetherecordsformtheunderlyingtable.WhenwepassanobjecttoaSession.save()method,hibernatereadsthestateofthevariablesofthatobjectandexecutesthenecessaryquery.Hibernateisextremelygoodtoolasfarasobjectrelationalmappingisconcern,butintermsofconnectionmanagementandtransactionmanagement,itlacksinperformanceandcapabilities.Sousuallyhibernateisbeingusedwithotherconnectionmanagementandtransactionmanagementtools.ForexampleapacheDBCPisusedforconnectionpoolingwiththehibernate.Hibernateprovidesalotofflexibilityinusage.ItiscalledLitearchitecturewhenweonlyuseobjectrelationalmappingcomponent.WhileinFullCreamarchitectureallthethreecomponentObjectRelationalmapping,ConnectionManagementandTransactionManagementareused.Hibernatearchitecturecanbeshownindetailinthefigure2.4Figure2.AdetailedHibernateArchiTectureHibernateQueryLanguageorHQLforshortisextremelypowerfulquerylanguage.HQLismuchlikeSQLandarecase-insensitive,exceptforthenamesoftheJavaClassesandproperties.HibernateQueryLanguageorHQLforshortisextremelypowerfulquerylanguage.HQLismuchlikeSQLandarecase-insensitive,exceptforthenamesoftheJavaClassesandproperties.HibernateQueryLanguageisusedtoexecutequeriesagainstdatabase.HibernateautomaticallygeneratesthesqlqueryandexecuteitagainstunderlyingdatabaseifHQLisusedintheapplication4.HQLisbasedontherelationalobjectmodelsandmakestheSQLobjectoriented.HibernateQueryLanguageusesClassesandpropertiesinsteadoftablesandcolumns.HibernateQueryLanguageisextremelypowerfulanditsupportsPolymorphism,AssociationsandislessverbosethanSQL.Thereareotheroptionsthatcanbeusedwhileusinghibernate3.TheseareQueryByCriteria(QBC)andQueryBYExample(QBE)-usingCriteriaAPIand5theNativeSQLqueries.Fullsupportforrelationaloperations-HQLpermitsrepresentingSQLqueriesintheformofobjects.HibernateQueryLanguageusesClassesandpropertiesinsteadoftablesandcolumns.ReturnresultasObject-TheHQLqueriesreturnthequeryresult(s)intheformofobject(s),whichiseasytouse.Thiseliminatestheneedofcreatingtheobjectandpopulatesthedatafromresultset.PolymorphicQueries-HQLfullysupportspolymorphicqueries.Polymorphicqueriesprovidequeryresultsalongwithallthechildobjectsifany.EasytoLearn-HibernateQueriesareeasytolearnanditcanbeeasilyimplementedintheapplications.SupportforAdvancefeatures-HQLcontainsmanyadvancedfeaturessuchaspagination,fetchandjoinwithdynamicprofiling,Inner/outer/fulljoinsandCartesianproducts.ItalsosupportsProjection,Aggregation(max,avg)andgrouping,Ordering,SubqueriesandSQLfunctioncalls.Databaseindependent-QuerieswritteninHQLaredatabaseindependent.UNDERSTANDINGANDIMPLEMENTATIONOFHIBERNATEMAPPING6Hibernatemappingdocumentsaresimplexmldocuments10.Herearesomeimportantelementsofthemappingfile:1.element:Thefirstorrootelementofhibernatemappingdocumentiselementbetweenthetagclasselement(s)arepresent3.2.element:Theelementmapstheclassobjectwithcorrespondingentityinthedatabase.Italsotellswhattableinthedatabasehastoaccessandwhatcolumninthattableitshoulduse.Withinoneelement,severalmappingsarepossible.3.element:Theelementisuniqueidentifiertoidentifyandobject.InfactelementmapwiththeprimarykeyofthetableinourcodeprimarykeymapstotheIDfieldofthetableCOMMUNICATE.Theattributesoftheidelementare:a)Name:Thepropertynameusedbythepersistentclass.b)Column:Thecolumnusedtostoretheprimarykeyvalue.C)TheJavadatatypeisused.d)unsaved-value:Thisisthevalueusedtodetermineifaclasshasbeenmadepersistent.Ifthevalueoftheidattributeisnull,thenitmeansthatthisobjecthasnotbeenpersisted.4.element:Themethodisusedtogeneratetheprimarykeyforthenewrecord.Hereissomeofthefrequentlyusedgenerators.a)Increment-Thisisusedtogenerateprimarykeysoftypelong,shortorintthatareuniqueonlybeusedintheclustereddeploymentenvironment.b)Sequence-Hibernatecanalsousethesequencestogeneratetheprimarykey.ItcanbeusedwithDB2,postgreSQL,Oracle,SAPDBdatabases.7c)Assigned-Assignedmethodisusedwhenapplicationcodegeneratestheprimarykey.5.element:ThepropertyelementsdefinestandardJavaattributesandtheirmappingintodatabaseschema.Thepropertyelementsupportsthecolumnchildelementtospecifyadditionalproperties,suchastheindexnameonacolumnoraspecificcolumntype.8附录2HIBERNATE技术促进高效的业务应用程序扩展摘要:本文讨论了休眠技术作为一种新型快捷的方式来访问大量的数据库,并重点介绍了如何通过它实现在面向对象的系统持久性的特点。它讨论了目前可用的Hibernate映射框架的细节。Hibernate提供的集合,客体关系,以及复杂的和复合类型的支持。除了保持对象,Hibernate也提供了丰富的查询语言来检索对象fROM中的数据库,以及一个高效的缓存层和Java管理扩展(JMX)的支持。Hibernate是一个强大的,高性能的,功能丰富的和非常受欢迎的ORM的Java解决方案。Hibernate的便利的基础上,常见的Java对象模型,以反映底层数据库结构的持久对象的发展。这种方法的进展的经营业绩在一定程度上,好生进步开发效率,并取得较好的经济性和实用性。此外,它比较和分析数据库的访问效率,由于基于Hibernate和JDBC两种机制。本文提供了深入了解Hibernate的技术实施和使用。关键词:休眠,HQL,ORM,数据库,SQL。引言企业应用程序开发的主要部分包括用于从选择的数据库积累和检索对象持久层的创建和维护1。许多企业采取建立自产自销,经常有错误,持久层。如果更改了底层的数据库架构,它可以是昂贵传播这些更改应用程序的其余部分。Hibernate的步骤,填补了这一空白,提供了一个易于使用和功能强大的对象关系持久化框架的Java应用程序。Hibernate是一个对象-关系映射(ORM)库,Java语言,提供了一个映射面向对象的领域模型到传统的关系型数据库的框架。通过更换高级别对象处理功能的持久性直接相关的数据库访问Hibernate解决了对象关系的阻抗失配问题。ORM是一块软件产品数据库和面向对象的编程语言之间的数据表示和翻译。Hibernate是一个这样的ORM解决方案,它是一个开源项目。在Hibernate2.1框架,赢得了奖项于2005年。Hibernate提供了对集合和对象的关系,以及复合类型的支持。它还提供了丰富的查询语言从数据库中检索对象,一个称职的缓存层,具有Java管理扩展(JMX)的支持。Hibernate是较小的GNU通用公共许可证,这是足够用于商业用途,以及开放源代码的应用程序下发布的。它支持多种数据库,包括Oracle和DB2,也是流行的开源数据库,如PostgreSQL和MySQL。工作的Hibernate而不是利用字节码处理或代码生成,Hibernate使用运行时反射来确定一个类的持久性。被持久化的对象在一个映射文件,它用于描述持久性字段和协会,以及定义持久化对象的任何子类或代理。映射文件被编译在应用程序启动的时间和必要的信息的一类供应框架2。除了它,它们被用于支持操作,如生成数据库架构或创建存根和Java源文件。一个Session工厂从映射文件的编译集合创建6。会话工厂提供9的机制来管理持久化类和Session接口。会话类提供持久性数据存储和应用程序之间的接口。Session接口封装了JDBC连接,它可以是用户管理或休眠控制,并且只打算使用一个单一的应用程序线程,然后关闭并丢弃。Hibernate的架构下面Figure1and图2描述了休眠的高层体系结构,即他们展示如何Hibernate使用数据库和配置数据,为应用程序提供持久化服务(以及持久的对象)。使用Hibernate,它需要创建Java类,表示该表在数据库中,然后在对应的类中的实例变量与数据库中的列。那么,Hibernate可以用于像选择,插入,更新在数据库上执行操作和删除表中的记录。Hibernate的自动创建的查询来执行这些操作。该Figure1describes休眠的高层体系结构。图1.基本的Hibernate架构冬眠体系结构具有以下三个主要组成部分。连接管理:数据库连接Hibernate的连接管理服务补助高效的管理。数据库连接数据库的最昂贵的部分,因为它需要大量的打开/关闭数据库连接的资源。交易管理:交易管理服务提供的能力,用户在同一时间执行多个数据库语句。对象关系映射:对象关系映射是映射数据表示从对象模型到关系数据模型的技术。hibernate的这部分是用来选择,插入,更新,查看和删除记录,形成基础表。当我们将对象传递给一个的session.save()方法,休眠读取该对象的变量的状态,并执行必要的查询。Hibernate是非常不错的工具,只要对象关系映射的关注,但在连接管理和事务管理方面,它缺乏在性能和功能。所以通常冬眠正在使用与管理和事务管理工具等CONNECTI。例如Apache的DBCP用于连接池与休眠。Hibernate提供了很多在使用的灵活性。这就是所谓的“精简版”的架构时,我们只使用了对象关系映射组件。而在“全脂”架构全部三个组件对象关系映射,连接管理和事务管理使用。冬眠架构可以显示详细介绍了在图2中。10图2.详细的Hibernate架构Hibernate查询语言H

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论