抑郁症健康,内容丰富有趣,生活中的好帮手!
抑郁症健康 > Hibernate最新英文资料翻译整理

Hibernate最新英文资料翻译整理

时间:2023-11-14 04:33:49

相关推荐

翻译&&英文技术资料

欢迎各位行业内朋友骚扰,哈哈。

7月29日

Hibernate ORM 5.3.3.Final User Guide

Working with both Object-Oriented software and Relational Databases can be cumbersome and time consuming. Development costs are significantly higher due to a paradigm mismatch between how data is represented in objects versus relational databases. Hibernate is an Object/Relational Mapping solution for Java environments. The term Object/Relational Mapping refers to the technique of mapping data from an object model representation to a relational data model representation (and visa versa).

同时面对面向对象的软件和关系型数据库是非常累赘并且相当耗时的事情。由于面向对象的数据表示方式和关系型数据库数据表示方式之间的规范差异导致开发成本明显攀升。Hibernate是一个针对java开发环境,解决面向对象和关系型数据库之间的映射方案。 Object/Relational Mapping这个项目涉及的技术是面向对象数据表示形式到关系型数据库的数据表示形式的模型映射。

Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities. It can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC. Hibernate’s design goal is to relieve the developer from 95% of common data persistence-related programming tasks by eliminating the need for manual, hand-crafted data processing using SQL and JDBC. However, unlike many other persistence solutions, Hibernate does not hide the power of SQL from you and guarantees that your investment in relational technology and knowledge is as valid as always.

Hibernate不仅可以实现从java类到数据库表的映射,本质是从Java数据到SQL数据格式,而且提供了查询和检索的功能。它有效节约了以前在人为处理SQL和JDBC的时间。减少了开发人员处理普遍的数据持久层的编程任务,减少的程度有多大,可以说之前95%的时间是花费在这种编程任务上的。但是,不像其他的持久层解决方案,Hibernate没有隐藏SQL的强大功能,你对关系型技术和知识的投入依旧是有效的。

Hibernate may not be the best solution for data-centric applications that only use stored-procedures to implement the business logic in the database, it is most useful with object-oriented domain models and business logic in the Java-based middle-tier. However, Hibernate can certainly help you to remove or encapsulate vendor-specific SQL code and will help with the common task of result set translation from a tabular representation to a graph of objects.

对于只是简单将数据存储在数据库中,然后实现相关的业务逻辑的应用,Hibernate可能不是最好的解决方案,它对于基于java的中间层最有用,而且这个中间层涉及到面向对象模型和业务逻辑时最有用。但是,Hibernate肯定可以帮助您删除或封装特定于供应商的SQL代码,并将帮助您完成将结果集从表格表示转换为对象图的常见任务。

系统要求:

Hibernate 5.2 and later versions require at least Java 1.8 and JDBC 4.2.

Hibernate 5.1 and older versions require at least Java 1.6 and JDBC 4.0.

Getting Started Guide

New users may want to first look through the Hibernate Getting Started Guide for basic information as well as tutorials. There is also a series of topical guides providing deep dives into various topics.

图1-1

获取开始指导手册

虽然使用Hibernate不需要具备SQL的强大背景,但它确实有很大的帮助,因为它可以归结为SQL语句。可能更重要的是理解数据建模原理。你可能想把这些资源作为一个好的起点:

重点是理解数据库建模原理,理解事务的基础知识和设计模式也很重要。

架构:如图1-1

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. The Java application makes use of the Hibernate APIs to load, store, query, etc its domain data. Here we will introduce the essential Hibernate APIs. This will be a brief introduction; we will discuss these contracts in detail later.

java应用程序数据访问层和关系型数据库之间是Hibernate。Java应用程序调用Hibernate APIs实现数据的入库、查询、下载等功能。

作为一个JPA提供者,Hibernate实现了Java持久化API规范,JPA接口和Hibernate特定实现之间的关联可以在下面的图中可视化:

I:接口;

C: 类

三个大类对应三个接口

A thread-safe (and immutable) representation of the mapping of the application domain model to a database. Acts as a factory for org.hibernate.Session instances. The EntityManagerFactory is the JPA equivalent of a SessionFactory and basically those two converge into the same SessionFactory implementation.

以Entity开头的接口是被JPA规范化的接口。

A SessionFactory is very expensive to create, so, for any given database, the application should have only one associated SessionFactory. The SessionFactory maintains services that Hibernate uses across all Session(s) such as second level caches, connection pools, transaction system integrations, etc.

创建SessionFactory是非常昂贵(耗费很多资源,非轻量级)的,因此,对于任何给定的数据库,应用程序应该只有一个关联的SessionFactory。会话工厂维护Hibernate在所有会话中使用的服务,如第二级缓存、连接池、事务系统集成等。

Session (org.hibernate.Session)

A single-threaded, short-lived object conceptually modeling a "Unit of Work" PoEAA. In JPA nomenclature, the Session is represented by an EntityManager.

Behind the scenes, the Hibernate Session wraps a JDBC java.sql.Connection and acts as a factory for org.hibernate.Transaction instances. It maintains a generally "repeatable read" persistence context (first level cache) of the application domain model.

Session(会话)对JDBC连接(connection)进行包装,充当hibernate事务用例的一个工厂。

Transaction (org.hibernate.Transaction)

A single-threaded, short-lived object used by the application to demarcate individual physical transaction boundaries. EntityTransaction is the JPA equivalent and both act as an abstraction API to isolate the application from the underlying transaction system in use (JDBC or JTA).

事务:单线程的,短生命周期的对象,用于分割单个物理事务边界。EntityTransaction是JPA规范化后的Transaction

将应用程序与底层事务系统隔离开来。

2、域模型

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).

Hibernate对持久对象性质几乎没有什么假设,不限于将其设计成Plain Old Java Object (POJO) / JavaBean。

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映射文件格式。但随着JPA的到来,现在大多数信息都以一种可在使用注释(和/或标准化XML格式)的ORM/JPA提供程序之间移植的方式进行了定义。本章将在可能的情况下重点介绍JPA映射。对于JPA不支持的Hibernate映射特性,我们将更喜欢Hibernate扩展注释。

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

SQL命令语句实现:

create table Contact (

id integer not null,

first varchar(255),

last varchar(255),

middle varchar(255),

notes varchar(255),

starred boolean not null,

website varchar(255),

primary key (id)

)

当Hibernate存在事,可以直接使用Java程序生成表:

@Entity(name = "Contact")

public static class Contact {

@Id

private Integer id;

private Name name;

private String notes;

private URL website;

private boolean starred;

//Getters and setters are omitted for brevity

}

@Embeddable

public class Name {

private String first;

private String middle;

private String last;

// getters and setters omitted

}

Entity:实体; Embeddable:嵌入式

2.2 命名策略

对象模型到关系型数据库映射部分是将对象模型的名称映射到相应的数据库名称。Hibernate将这一过程拆分成2步完成。

第一步:从域模型映射确定一个合适的逻辑名称;

第二步:将逻辑名称解析为物理名称;

Example 2. Example PhysicalNamingStrategy implementation

/** Hibernate, Relational Persistence for Idiomatic Java** License: GNU Lesser General Public License (LGPL), version 2.1 or later.* See the lgpl.txt file in the root directory or </licenses/lgpl-2.1.html>.*/package org.hibernate.userguide.naming;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.TreeMap;import org.hibernate.boot.model.naming.Identifier;import org.hibernate.boot.model.naming.PhysicalNamingStrategy;import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;import mons.lang3.StringUtils;/*** An example PhysicalNamingStrategy that implements database object naming standards* for our fictitious company Acme Corp.* <p/>* In general Acme Corp prefers underscore-delimited words rather than camel casing.* <p/>* Additionally standards call for the replacement of certain words with abbreviations.** @author Steve Ebersole*/public class AcmeCorpPhysicalNamingStrategy implements PhysicalNamingStrategy {private static final Map<String,String> ABBREVIATIONS = buildAbbreviationMap();@Overridepublic Identifier toPhysicalCatalogName(Identifier name, JdbcEnvironment jdbcEnvironment) {// Acme naming standards do not apply to catalog namesreturn name;}@Overridepublic Identifier toPhysicalSchemaName(Identifier name, JdbcEnvironment jdbcEnvironment) {// Acme naming standards do not apply to schema namesreturn name;}@Overridepublic Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment) {final List<String> parts = splitAndReplace( name.getText() );return jdbcEnvironment.getIdentifierHelper().toIdentifier(join( parts ),name.isQuoted());}@Overridepublic Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEnvironment) {final LinkedList<String> parts = splitAndReplace( name.getText() );// Acme Corp says all sequences should end with _seqif ( !"seq".equalsIgnoreCase( parts.getLast() ) ) {parts.add( "seq" );}return jdbcEnvironment.getIdentifierHelper().toIdentifier(join( parts ),name.isQuoted());}@Overridepublic Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment) {final List<String> parts = splitAndReplace( name.getText() );return jdbcEnvironment.getIdentifierHelper().toIdentifier(join( parts ),name.isQuoted());}private static Map<String, String> buildAbbreviationMap() {TreeMap<String,String> abbreviationMap = new TreeMap<> ( String.CASE_INSENSITIVE_ORDER );abbreviationMap.put( "account", "acct" );abbreviationMap.put( "number", "num" );return abbreviationMap;}private LinkedList<String> splitAndReplace(String name) {LinkedList<String> result = new LinkedList<>();for ( String part : StringUtils.splitByCharacterTypeCamelCase( name ) ) {if ( part == null || part.trim().isEmpty() ) {// skip null and spacecontinue;}part = applyAbbreviationReplacement( part );result.add( part.toLowerCase( Locale.ROOT ) );}return result;}private String applyAbbreviationReplacement(String word) {if ( ABBREVIATIONS.containsKey( word ) ) {return ABBREVIATIONS.get( word );}return word;}private String join(List<String> parts) {boolean firstPass = true;String separator = "";StringBuilder joined = new StringBuilder();for ( String part : parts ) {joined.append( separator ).append( part );if ( firstPass ) {firstPass = false;separator = "_";}}return joined.toString();}}

如果觉得《Hibernate最新英文资料翻译整理》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。