自学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 Hibernate uses a registry of basic types when it needs to resolve a specific org.hibernate.type.Type.

  基础的值类型通常映射一个数据库列,到一个单个的,非聚合的java类型。HIbernate提供了大量的内置基础类型,遵循原生的映射被JDBC规范推荐。

  当他需要去解析指定的org.hibernate.type.Type.时在HIbernate内部使用一个基础类型的注册

  

2.3.1. Hibernate-provided BasicTypes(HIbernate提供的基础类型)

使用HIbernate-java8类型仅添加了HIbernate-java依赖到你的类路径,剩下的依赖HIbernate能够处理。

  These mappings are managed by a service inside Hibernate called the org.hibernate.type.BasicTypeRegistry, which essentially maintains a map oforg.hibernate.type.BasicType (a org.hibernate.type.Type specialization) instances keyed by a name. That is the purpose of the "BasicTypeRegistry key(s)" column in the previous tables.

  通过一个服务内部的HIbernate调用 org.hibernate.type.BasicTypeRegistry管理这些映射,本质上维持一个映射的org.hibernate.type.BasicType (a org.hibernate.type.Type specialization) 实例需要通过一个名字。这个目的的“BasicTypeRegistry key(s)”列里面之前的表。

2.3.2. The @Basic annotation

  Strictly speaking, a basic type is denoted with with the javax.persistence.Basic annotation. Generally speaking, the @Basic annotation can be ignored, as it is assumed by default. Both of the following examples are ultimately the same.

  严格来说,一个基础的类型用javax.persistence.Basic注解来表示。通常来说,@Basic注解能够被忽略,因为他假设在默认的情况下,就像下面的例子最后都是一样的。

  example 3. @Basic declared explicitly

  @Basic显示声明例子

  

@Entity(name = "Product")
public class Product {

    @Id
    @Basic
    private Integer id;

    @Basic
    private String sku;

    @Basic
    private String name;

    @Basic
    private String description;
}

Example 4. @Basic being implicitly implied

含蓄的暗示

@Entity(name = "Product")
public class Product {

    @Id
    private Integer id;

    private String sku;

    private String name;

    private String description;
}

JPA规范严格的限制可标记为基础的java类型一下清单:

  。。。

任何其他的类型要实现序列化(JPA的“支持”序列化的类型直接序列化它们到数据库)

如果提供者移植性是一个问题,你应该严格的去使用基础类型。注意JPA2.1已经添加javax.persistence.AttributeConverter的概念去帮助缓解这些问题。

The @Basic annotation defines 2 attributes.

optional - boolean (defaults to true)

Defines whether this attribute allows nulls. JPA defines this as "a hint", which essentially means that it effect is specifically required. As long as the type is not primitive, Hibernate takes this to mean that the underlying column should be NULLABLE.

fetch - FetchType (defaults to EAGER)

Defines whether this attribute should be fetched eagerly or lazily. JPA says that EAGER is a requirement to the provider (Hibernate) that the value should be fetched when the owner is fetched, while LAZY is merely a hint that the value be fetched when the attribute is accessed. Hibernate ignores this setting for basic types unless you are using bytecode enhancement. See the BytecodeEnhancement for additional information on fetching and on bytecode enhancement.

@Basic注解定义了两个三属性。

optional - boolean(默认为true)

  定义这个属性是否为空值。JPA定义这个作为“一个示意”,本质的意思是它的影响是明确需要的。只要不是原始类型,HIbernate将它认为底层的列可以为空。

fetch-FetchType(默认为立即)

  定义这个属性是否是立即加载或是懒加载。JPA说HIbernate提供者EAGER是必须当值被取得从这个所有物取得时,当访问这个属性时LAZY才调用这个值被取得。HIbernate忽略了设置基础类型,除非你使用字节码增强。

2.3.3. The @Column annotation

  JPA defines rules for implicitly determining the name of tables and columns. For a detailed discussion of implicit naming see Naming.

For basic type attributes, the implicit naming rule is that the column name is the same as the attribute name. If that implicit naming rule does not meet your requirements, you can explicitly tell Hibernate (and other providers) the column name to use.

  JPA定义规则隐式地确定表名和列名。

  基础类型属性,隐式命名规则中列名与属性名一样。如果隐式命名规则不能满足你的需要,你能够显示的告诉HIbernate(并且提供其他)列名给它使用。

Example 5. Explicit column naming(显示列名命名 例5)

@Entity(name = "Product")
public class Product {

    @Id
    private Integer id;

    private String sku;

    private String name;

    @Column( name = "NOTES" )
    private String description;
}

  Here we use @Column to explicitly map the description attribute to the NOTES column, as opposed to the implicit column name description.

The @Column annotation defines other mapping information as well. See its Javadocs for details.

   我们使用@Column显示地映射描述的属性去说明这个列名,作为相对于隐式列名的秒速。@Column注解也定义了其他的映射信息,查看Javadocs详情。。。

时间: 2024-08-24 23:01:47

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

小白自学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. 域模型一词来自数据建模的领域,它是你在工作中是最终地描述的问题领域模

小白自学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

Beautiful Soup 4.2.0 文档

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

第一百一十三节,JavaScript文档对象,DOM基础

JavaScript文档对象,DOM基础 学习要点: 1.DOM介绍 2.查找元素 3.DOM节点 4.节点操作 DOM(Document Object Model)即文档对象模型,针对HTML和XML文档的API(应用程序接口).DOM描绘了一个层次化的节点树,运行开发人员添加.移除和修改页面的某一部分.DOM脱胎于Netscape及微软公司创始的DHTML(动态HTML),但现在它已经成为表现和操作页面标记的真正跨平台.语言中立的方式. 一.DOM介绍 DOM中的三个字母,D(文档)可以理解

下载大数据实战课程第一季Python基础和网络爬虫数据分析

python语言近年来越来越被程序相关人员喜欢和使用,因为其不仅简单容易学习和掌握,而且还有丰富的第三方程序库和相应完善的管理工具:从命令行脚本程序到gui程序,从B/S到C/S,从图形技术到科学计算,软件开发到自动化测试,从云计算到虚拟化,所有这些领域都有python的身影:python已经深入到程序开发的各个领域,并且会越来越多的人学习和使用. 大数据实战课程第一季Python基础和网络爬虫数据分析,刚刚入手,转一注册文件,视频的确不错,可以先下载看看:链接:http://pan.baidu

【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的,几百人混战的场面,在当时 低端的电脑下面,一点都不逊色.如今 手机 的配置,正如 过去的 低端电脑,他的处理速度

PDF文档:Itext 的基础知识

一.Itext简介 1.API地址:javadoc/index.html 如 D:/MyJAR/原JAR包/PDF/itext-5.5.3/itextpdf-5.5.3-javadoc/index.html 2.功能:a Free Java-PDF 3.中文支持:iTextAsian.jar,现在高版本Itext不支持语言包. 4.使用的版本:iTextpdf-5.0.0.jar, iTextAsian-2.0.jar 二.Itext API (一)PDF文档生成的5步 /** * 5步生成一个