小白自学HIBERNATE5.0文档第一季之域模型

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分类类型分为两组:
 

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。

                蛋疼的翻译。。。。云里雾里。。。。

时间: 2024-08-08 21:53:42

小白自学HIBERNATE5.0文档第一季之域模型的相关文章

小白自学hibernate5.0文档第一季之架构篇

果然,hibernate的底层是由JDBC实现的. --Java Data Base Connectivity,Java数据库连接 --翻译得不到位,敬请批评 Hibernate, as an ORM solution, effectively "sits between" the Java application data access layer and the Relational Database, as can be seen in the diagram above. Th

自学HIBERNATE5.0文档第一季之基础类型篇

2.3. Basic Types Basic value types usually map a single database column, to a single, non-aggregated Java type. Hibernate provides a number of built-in basic types, which follow the natural mappings recommended by the JDBC specifications. Internally

Beautiful Soup 4.2.0 文档

Beautiful Soup 4.2.0 文档 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你节省数小时甚至数天的工作时间. 这篇文档介绍了BeautifulSoup4中所有主要特性,并且有小例子.让我来向你展示它适合做什么,如何工作,怎样使用,如何达到你想要的效果,和处理异常情况. 文档中出现的例子在Python2.7和Python3.2中的执行结果相

小白如何写需求文档

上学期在跟着网站里的学长学姐学了许多东西,假期我们需要自己做一套网站签到OA出来,昨天刚刚把需求文档定下,万事开头难,我把迈出的第一步记录下来,也给第一次写文档的小伙伴一些建议. 第 一次写,难免无从下手,在网上查找了大量的需求文档范例,网上也有模板,不过模板上东西很多,有些我还并不太了解,也不太适用于自己我们要做的OA. 既然是需求文档,那就应该根据项目实际情况去写文档,所以我们在写文档时注重的是我们需不需要,而非和模板是否符合.接下来,是我们写文档的步骤. 1.定框架 首先要把整篇文档需要的

【PyTorch v1.1.0文档研习】60分钟快速上手

阅读文档:使用 PyTorch 进行深度学习:60分钟快速入门. 本教程的目标是: 总体上理解 PyTorch 的张量库和神经网络 训练一个小的神经网络来进行图像分类 PyTorch 是个啥? 这是基于 Python 的科学计算包,其目标是: 替换 NumPy,发挥 GPU 的作用 一个提供最大灵活性和速度的深度学习研究平台 起步 PyTorch 中的 Tensor 类似于 NumPy 中的 ndarray(这一点类似于 TensorFlow),只不过张量可以充分利用 GPU 来进行加速计算.

GameUnity 2.0 文档(三) 纸片人八方向

DirectSprite类 有别于 上篇文档出现的 AnimationSprite类 (从头播放到尾) 这个类根据 path的图,如果是 8*8 64个图 八方向,可以设置长宽和 角度 角度 代表 8 个方向. Camera2DAngle类 摄像机 旋转,2d 模仿3d 观察 遍历全身. Move2DAngle 类 八方向寻路 动画控制 //////未完,待续

GameUnity 2.0 文档(二) 纸片人系统

本想快速的 把 之前写的类库,一股脑的 给大家 ,但又觉得,如 msdn那样的 文档,并不能给 初学者 所能接受. 因为 大部分人 对 api 还是比较陌生,也不愿意 去研究和组合. 那么 今天我选用另外一种方式 来 给大家 介绍api,希望大家能学到本领. 今天我给大家 做一个纸片人系统.所谓的纸片人,大家一定不会陌生,最经典的就是 ---三国群英传 你们很难看出,其实他是 2d的,几百人混战的场面,在当时 低端的电脑下面,一点都不逊色.如今 手机 的配置,正如 过去的 低端电脑,他的处理速度

Domino表单保存后,文档默认增加$Readers域的设置

[背景] 今天遇到一个奇怪的问题,一个表单一保存后,文档属性中会有一个$Readers域.查遍了各种资料无果. [原因] 表单属性-最后一个选项卡-去掉"所有读者及更高权限者"并且选择指定的角色.截图如下:

GameUnity 2.0 文档(四) 网格+四叉树 最优碰撞检测

在写之前,必须对 前一篇文档补充一下. Camera2DAngle类是 摄像机旋转 2d人物360度,PlayerMove是人物移动. 这两个类 都可以 360 °  场景旋转人物也跟着旋转. 但不能同时用. 前者更倾向于 不移动的 人物.后者倾向于 移动的人物. 但精度 前者 高于 后者.具体根据项目需求 选择. 今天 介绍的类 CollisionDetection  碰撞检测类 public GameObject GridPrefab;//网格块材料 public int RangeLeng