ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:169.41KB ,
资源ID:16825535      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/16825535.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Hibernate 简化继承映射 外文翻译Word文档格式.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Hibernate 简化继承映射 外文翻译Word文档格式.docx

1、ll describe that process in this article.)3. Copy the XML configuration files to your applications CLASSPATH. Youll notice that you dont have to modify any Java objects to support the framework. Imagine, for instance, that you needed to somehow change a database table that your Java application used

2、 - by renaming a column, for example. Once youd changed the table, all youd have to do to update your Java application would be to update the appropriate XML configuration file. You wouldnt need to recompile any Java code. Hibernate Query Language (HQL)Hibernate provides a query language called Hibe

3、rnate Query Language (HQL), which is quite similar SQL. For those of you who prefer good old-fashioned SQL queries, Hibernate still gives you the opportunity to use them. But our supporting example will use HQL exclusively. HQL is quite simple to use. You will find all the familiar keywords you know

4、 from SQL, like SELECT, FROM, and WHERE. HQL differs from SQL in that you dont write queries directly on your data model (that is, on your tables, columns, etc.), but rather on you Java objects, using their properties and relationships. Listing 1 illustrates a basic example. This HQL code retrieves

5、all Individuals whose firstName is John. Listing 1. Basic HQL QuerySELECT * FROM eg.hibernate.mapping.dataobject.Individual WHERE firstName = JohnYou can refer to the HQL reference material on the Hibernate Website if you want to learn more about HQL syntax. XML configuration filesThe core of Hibern

6、ates functionality resides inside XML configuration files. These files must reside in your applications CLASSPATH. We placed them in the config directory of our sample code package The first file that well examine is hibernate.cfg.xml. It contains information regarding your data source (DB URL, sche

7、ma name, username, password, etc.) and references to other configuration files that will contain your mapping information. The remaining XML files allow you to map Java classes against database tables. We will take a closer look at those files later, but it is important to know that their filenames

8、follow the pattern ClassName.hbm.xml. Our supporting exampleIn this article, well examine a basic example that illustrates how Hibernate works and puts to good use three different strategies under which you can use Hibernate to do your object-relational mapping. Our example application will be used

9、by an insurance company that must keep legal records of all the property rights that its customers are insured for. Weve provided the full source code with this article; this code provides basic functionality from which you could build a full-fledged application, such as a Web or Swing application.

10、Our example assumes a classic use case for this kind of application. The user would provide the search criteria for any type of customer (individual, corporation, government agency, etc.), and would then be presented with a list of all customers matching the specified criteria - even if these are di

11、fferent types of customers. The user could access a more detailed view of a specific customer from that same list. In our application, a property right is represented by the Right class. A Right can either be a Lease or a Property. A Right is owned by a customer. To represent our customer, well use

12、the generic class Person. A Person can either be an Individual or a Corporation. Of course, the insurance company must know the Estates to which those Rights are assigned. An Estate is a very generic term, youll agree. So, well use the Land and Building classes to give our developers more comprehens

13、ive objects to work with. From this abstract, we can develop the class model shown in Figure 1:Figure 1. Complete Class ModelOur database model was designed to cover the three different strategies well discuss in this article. For the Right hierarchy, well use a single table (TB_RIGHT) and map to th

14、e correct class using the DISCRIMINATOR column. For the Person hierarchy, well use what we call a super table (TB_PERSON) that will share the same IDs with two other tables (TB_CORPORATION and TB_INDIVIDUAL). The third hierarchy (Estate) uses two different tables (TB_BUILDING and TB_LAND) linked by

15、a foreign key defined by the combination of two columns (REF_ESTATE_ID and REF_ESTATE_TYPE). Figure 2. Complete data modelSetting up the databaseHibernate supports a wide variety of RDBMSs, and any of them should work with our sample. However, the sample code and the text of this article have been t

16、ailored for HSQLDB, a fully functional relational database written entirely in the Java language. In the sql directory of the sample code package, you will find a file named datamodel.sql. This SQL script will create the data model used in our example. Setting up the Java projectAlthough you can alw

17、ays build and execute the sample code using the command line, you may want to consider setting up the project in an IDE for better integration. Within the sample code package, youll find the following directories: config, which contains all the samples XML configuration files (mapping, Log4J, etc.)

18、data, which contains configuration files used by HSQLDB. You will also find a batch file named startHSQLDB.bat that you may use to launch the database. src, contains all the samples source code. Be sure to copy the required Java libraries and XML configuration files to you applications CLASSPATH. Th

19、e code needs only the Hibernate and HSQLDB libraries in order to compile and run properly.Strategy 1: One table per subclass (Persons)In our first strategy, well look at how to map our Person hierarchy. Youll notice that the data model is very close to our class model. As a result, well use a differ

20、ent table for each class in the hierarchy, but all these tables must share the same primary key (well explain that in more detail momentarily). Hibernate will then use this primary key when it inserts new records into the database. It will also make use of this same primary key to perform JOIN opera

21、tions when accessing the database.Now we need to map our object hierarchy to our table model. We have three tables (TB_PERSON, TB_INDIVIDUAL, and TB_CORPORATION). As we mentioned above, they all have a column named ID as a primary key. Its not mandatory to have a shared column name like this, but it

22、 is considered good practice - and it makes it a lot easier to read the generated SQL queries. In the XML mapping file, shown in Listing 2, youll notice that the two concrete classes are declared as inside the Person mapping definition. The XML element is mapped to the primary key for the top-level

23、table TB_PERSON, while the elements (from each subclass) are mapped to the matching primary keys of the TB_INDIVIDUAL and TB_CORPORATION tables.Listing 2. Person.hbm.xml!DOCTYPE hibernate-mapping PUBLIC -/Hibernate/Hibernate Mapping DTD 2.0/EN hibernate-mapping /idset name=rights lazy=falsekey colum

24、n=REF_PERSON_IDone-to-many class=eg.hibernate.mapping.dataobject.Right /setjoined-subclass name=eg.hibernate.mapping.dataobject.IndividualTB_INDIVIDUALproperty name=firstNameFIRST_NAME type=java.lang.StringlastNameLAST_NAME/joined-subclasseg.hibernate.mapping.dataobject.CorporationTB_CORPORATIONname

25、NAMEstringregistrationNumberREGISTRATION_NUMBER/class/hibernate-mappingSaving a new instance of Individual form our Java code with Hibernate is pretty straightforward, as shown in Listing 3:Listing 3. Saving a new instance of Individualpublic Object create(Object object) Session session = null; try session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); session.save(object); session.fl

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1