小白自學HIBERNATE5.0文檔第一季之領域模型

來源:互聯網
上載者:User

標籤:ext   describe   tps   生命週期   ble   效果   har   nbsp   資料   

2. Domain Model

  The term domain model comes from the realm of data modeling. It is the model that ultimately describes the problem domain you are working in. Sometimes you will also hear the term persistent classes.

  領域模型一詞來自資料建模的領域,它是你在工作中是最終地描述的問題領域模型。有時你也將會聽到持久化類這個術語。

  Ultimately the application domain model is the central character in an ORM. They make up the classes you wish to map. Hibernate works best if these classes follow the Plain Old Java Object (POJO) / JavaBean programming model. However, none of these rules are hard requirements. Indeed, Hibernate assumes very little about the nature of your persistent objects. You can express a domain model in other ways (using trees of java.util.Map instances, for example).

  最終的應用程式定義域模型是ORM中的控制角色。它們組成了你希望去映射的類。Hibernate效果最好,如果你遵循普通的JAVA對象(POJO)/JavaBean 設計模型。然而,這些都不是硬要求。的確,Hibernate 承擔地非常少關於你的持久化對象。你能夠在其他方面表達領域模型(例如使用Map執行個體樹狀結構)。

  Historically applications using Hibernate would have used its proprietary XML mapping file format for this purpose. With the coming of JPA, most of this information is now defined in a way that is portable across ORM/JPA providers using annotations (and/or standardized XML format). This chapter will focus on JPA mapping where possible. For Hibernate mapping features not supported by JPA we will prefer Hibernate extension annotations.

  從曆史的觀點來說使用Hibernate將需要使用它的專有的XML對應檔格式化為了這個目的(這裡指格式化Model),隨著JPA的到來,大多數資訊現在定義很便捷通過ORM/JAP提供使用註解(或者是標準的XML格式)。這章節將集中的JPA映射在可能的情況下。

 

2.1. Mapping types

  Hibernate understands both the Java and JDBC representations of application data. The ability to read/write this data from/to the database is the function of a Hibernate type. A type, in this usage, is an implementation of the org.hibernate.type.Type interface. This Hibernate type also describes various aspects of behavior of the Java type such as how to check for equality, how to clone values, etc.

  Hibernate 懂得Java和JDBC應用程式資料的表示。能讀/寫資料到/從資料庫是HIbernate類型的功能。一個類型,這種用法是 org.hibernate.type.Type 介面的實現。

HIbernate類型也描述各種Java類型的行為方面,例如怎樣去檢查相等,怎樣去複製值,等等。

  To help understand the type categorizations, let’s look at a simple table and domain model that we wish to map.

  去協助理解這個類型分類,讓我們看一個簡單的表,我們希望去映射域到模型。



In the broadest sense, Hibernate categorizes types into two groups: 
 
廣泛的意義上,HIbernate分類類型分為兩組:
  • Value types

  • Entity types

 
2.1.1. Value types

  A value type is a piece of data that does not define its own lifecycle. It is, in effect, owned by an entity, which defines its lifecycle.

 一個實值型別是一個不能定義它自己的生命週期資料的片段,由一個實體,定義它的生命週期。
  
  
Looked at another way, all the state of an entity is made up entirely of value types. These state fields
or JavaBean properties are termed persistent attributes. The persistent attributes of the Contact class are
value types.
  另一方面,所有實體的聲明組成完整地實值型別。這些聲明屬性或者JavaBean屬性
是持久化屬性的術語。這個持久化Contact類的屬性就是實值型別。

  Value types are further classified into three sub-categories:

  實值型別進一步分類為3個子類別:

  Basic types

    in mapping the Contact table, all attributes except for name would be basic types. Basic types are discussed in detail in Basic Types

  Embeddable types

    the name attribute is an example of an embeddable type, which is discussed in details in Embeddable Types

  Collection types

    although not featured in the aforementioned example, collection types are also a distinct category among value types. Collection types are further   discussed in Collections

  基本類型:

    映射到Contact表,所有屬性除了名字作為基礎類型。

  可嵌入類型:

    名字屬性是一個巢狀型別的例子。

  集合類型:雖然不是在上面提到的特性,集合類型也是一個有別於實值型別的分類。

2.1.2. Entity types

  Entities, by nature of their unique identifier, exist independently of other objects whereas values do not. Entities are domain model classes which correlate to rows in a database table, using a unique identifier. Because of the requirement for a unique identifier, entities exist independently and define their own lifecycle. The Contact class itself would be an example of an entity.

Mapping entities is discussed in detail in Entity.

  

  實體,通過它們唯一識別碼的本質,獨立於其他對象而值不存。實體領域模型類關聯到資料中的列,使用唯一的標識符。因為需要一個唯一識別碼,實體存在映射實體的描述詳情在Entity這一節裡。

  

2.2. Naming strategies

  Part of the mapping of an object model to the relational database is mapping names from the object model to the corresponding database names. Hibernate looks at this as 2 stage process:

  • The first stage is determining a proper logical name from the domain model mapping. A logical name can be either explicitly specified by the user (using @Column or @Table e.g.) or it can be implicitly determined by Hibernate through an ImplicitNamingStrategy contract.

  • Second is the resolving of this logical name to a physical name which is defined by thePhysicalNamingStrategy contract.

  

  物件模型的映射部分關聯資料庫映射名字從物件模型到相應的資料庫名字。HIbernate看著兩階段過程:

  第一階段是確定從領域模型映射適當地符合邏輯的名字。使用一個邏輯名字能清楚的指定(使用@Column或 @Table e.g.)或者能 隱示的確定通過HIbernate的ImplicitNamingStrategy約定。

  第二是解析邏輯名到實體名稱定義通過PhysicalNamingStrategy 約定。

  曆史的命名策略規約

  曆史上HIbernate定義只是一個單例org.hibernate.cfg.NamingStrategy。單一的NamingStrategy規約實際上結合分離了現在模式化的關注點如同ImplicitNamingStrategy和PhysicalNamingStrategy.而且NamingStrategy規約經常不夠靈活去正確的應用給定的命名“規則”,也應為API缺少資訊去判定或因為API太誠實不能很好定義。

  由於這些限制,NamingStrategy曾棄用然後移除而贊成使用ImplicitNamingStrategy and PhysicalNamingStrategy

 

  At the core, the idea behind each naming strategy is to minimize the amount of repetitive information a developer must provide for mapping a domain model.

  中心思想,這個主意後面的每個命名策略資訊開發人員必須提供的映射領域模型使大量的重複減小到最小。

  JPA相容性

  JPA定義繼承規則關於隱式邏輯名推測。如果JPA提供者可移植性是一個主要地關注點,或者如果你真的只是像JPA定義隱式的命名規則,那麼可以堅持使用預設的ImplicitNamingStrategyJpaCompliantImpl 。同樣,JPA定義不分離邏輯名和實體名稱字。如果JPA提供者可移植性是重要的,應用程式應該不去指定這個策略PhysicalNamingStrategy。

 

 

 

                蛋疼的翻譯。。。。雲裡霧裡。。。。

 

 

 

 

小白自學HIBERNATE5.0文檔第一季之領域模型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.