hibernate阅读1.1.1关系数据库

understanding object/relational persistence-- 理解对象 / 关系 (OR) 持久化机制

 

The approach to managing persistent data has been a key design decision in evry software project we've worked on.

在我工作过的每个软件项目中,管理数据持久化问题都是一个关键设计决策。

 

Given that persistent data isn't a new or unusual requirement for java applicatios, you'd expect to be able to make

 

a simple choice among similar, well-established persistence solutions.

持久化数据不是一个新鲜的不太寻常的需求 ( 是个通用的需求 ) ,你肯定希望能够在相似、完好的持久解决方案中做一个简单的选择。

 

Think of web application frameworks (Structs versus WebWork),GUI component frameworks(Swing versus SWT), or template

 

engines (JSP versus Velocity). Each of the competing solutions has various advantages and disadvantages, but they

 

all share the same scope and overall approach.

考虑一下 WEB 应用框架 (Structs WebWork) GUI 组件框架 (Swing SWT) ,或者模板引擎 (JSP Velocity). 每个竞争的解决方案都有

 

其优势和劣势,但总体上说手法和处理问题的方式是相同的 ( 理念一致 )

 

 

Unfortunately, this isn't yet the case with persistence technologies, where we see some wildly differing solutions

 

to the same problem.

不幸的是在持久化技术方面还没有一致的理念,我们可以看到对同一问题完全不同的解决方案。

For serveral years, persistence has been a hot topic of debate in the Java community. Many developers don't even

 

agree on the scope of the problem.

多年来,持久化是 JAVA 社区一个热点争论的话题。很多开发者甚至不能为问题的范围取得一致,遑论解决。

 

Is persistence a problem that is already solved by relational technology and extensions such as stored procedures,

 

or is it a more pervasive problem that must be addressed by special Java component models, such as EJB entity benas?

持久化问题是否被关系数据库技术如存储过程解决?或者这是一个普遍问题,需要用特殊的 JAVA 组件模型如 EJB 实体 bean 解决?

 

Should we hand-code even the most primitive CRUD(create, read, update, delete) operations in SQL and JDBC, or should

 

this work be automated?

 

我们应该手工用 JDBC SQL 编写增查改删操作 ( 我喜欢的方式 ) ,还是应该让这些操作自动化?

How do we achieve portability if every database management system has its own SQL dialect?

如果美国数据库系统有自己的方言,我们如何获得可移植性?

 

Should we abandon SQL completely and adopt a different database technology, such as object database systems?

 

我们应该完全放弃 SQL 并采用一种不同的数据库技术,如面向对象数据库系统吗?

 

Debate continues, but a solution called object/relational mapping (ORM) now has wide acceptance.Hibernate is an open

 

source ORM service implementation.

争论在继续,但一种称为 ORM 的解决方案目前被广泛接受。 Hibernate 就是一个开源的 ORM 服务实现。

 

Hibernate is an ambitious project that aims to be a complete solution to the problem of managing persistent data in

 

Java.

Hibernate 是一个野心勃勃的项目,它的目标是为 JAVA 管理持久化数据提供完整的解决方案

 

It mediates the application's interaction with a relational database, leaving the developer free to concentrate on

 

the business problem at hand.

它作为应用于关系数据库之间的媒介,使开发人员专注于业务逻辑。

 

Hibernate is a nonintrusive solution.

Hibernate 是一个非侵入解决方案

 

You aren't required to follow many Hibernate-specific rules and design patterns when writing your business logic and

 

persistent classes; thus, Hibernate integrates smoothly with most new and existing applications and doesn't require

 

disruptive changes to the rest of the application.

当你写业务逻辑和持久化类时,不必遵循很多 Hibernate 独有的规则和模式。因此, hibernate 可以平滑的集成到现有的应用中而不对

 

应用的其他部分产生破坏性修改。

 

This book is about Hibernate. We'll cover basic and advanced features and describe some ways to develop new

 

applications using Hibernate.

这本书是关于 Hibernate 的。我们将描述基础和高级特性,并描述一些用 hibernate 开发新应用的方法。

 

Often, these recommendations won't even be specific to hibernate. Sometimes they will be our ideas about the best

 

ways to do things when working with persistent data, explained in the context of hibernate.

通常我们的建议不特别针对 hibernate. 有时候是我们对于持久化数据的最佳做事方式的说明,只是在 hibernate 的语境下表达出来。

 

This book is also about Java Persistence, a new standard for persistence that is part of the also updated EJB 3.0

 

specification.

这本书也是关于 JAVA 持久化标准的,新标准时 EJB 3.0 规范的一部分。

 

Hibernate implements Java persistence and supports all the standardized mappings, queries, and APIs.

Hibernate 实现了 JAVA 持久化标准并支持所有的映射、查询和 API

 

Before we can started with Hibernate, however, you need to understand the core problems of object persistence and

 

object/relational mapping. This chapter explains why tools like Hibernate and specifications such as Java

 

Persistence and EJB 3.0 are needed.

 

在开始介绍 Hibernate 之前,你需要理解对象持久化, ORM 的核心问题。 本章解释了 hibernate JP,EJB3.0 存在的原因。

 

First, we define persistent data management in the context of object-oriented applications and discuss the

 

relationship of SQL, JDBC, and JAVA, the underlying technologies and standards that Hibernate is built on.

首先我们定义持久化数据管理的范围在 OO 应用,并讨论了 SQL, JDBC JAVA 的关系, hibernate 基于的底层技术和标准

 

We then discuss the socalled object/relational paradigm mismatch and the generic problems we encounter in object-

 

oriented software development with relational databases. These problems make it clear that we need tools and

 

patterns to minmize the time we have to spend on the persistence-related code of our applications.

接着我们讨论了所谓对象、关系适配问题和在面向对象开发中应用数据库遇到的普遍问题。这些问题使得我们需要工具和模式来节省

 

开发持久关系代码所花费的时间。

 

After we look at alternative tools and persistence mechanisms, you'll see that ORM is the best available solution

 

for many scenarios.

当你看了很多可选的工具和持久方案后,你会发现 ORM 在很多情况下是最好的解决方案。

 

Our discussion of the advantages and drawbacks of ORM will give the full background to make the best decision when

 

picking a persistence solution for your own project.

我们关于 ORM 优缺点的讨论将给你很好的背景知识,帮助你在你的项目选择持久化方案是做出最佳决策。

 

We also take a look at the various Hibernate software modules, and how you can combine them to either work with

 

Hibernate only, or with Java Persistence and EJB 3.0-compliant features.

我们也介绍了 hibernate 软件的不同模块,不仅你可以将这些模块在 hibernate 中使用,也可以用于实现 EJB 3.0 标准特性。

 

The best way to learn Hibernate isn't necessarily linear. We understand that you may want to try Hibernate right

 

away. If this is how you'd like to proceed, skip to the second chapter of this book and have a look at the "Hello

 

World" example and set up a project. We recommend that you return here at some point as you circle through the book.

 

That way, you'll be prepared and have all the background concepts you need for the rest of the material.

 

最好的学习 Hibernate 的路线不是线性的。我理解你急于想尝试 hibernate 的心情,如果急于尝试,请跳到第二章,那里有个 Hello

 

world 的例子。不过我还是建议你适当的时机再回来读本章。

 

1.1 Whate is persistence?

Almost all applications require persistent data. Persistence is one of the fundamental concepts in application

 

development.

差不多所有应用都需要持久化 数据。持久化是应用开发的一个关键点。

 

If an information system didn't preserve data when it was powered off, the system would be of little practical use.

如果一个系统在关电视不需要保存数据,这个习题那个将无实际用途。

 

 

When we talk about persistence in JAVA, we're normally talking about storing data in a relational database using

 

SQL. We'll start by taking a brief look at the technology and how we use it with Java.

当我们谈论 JAVA 持久化,我们通常是说用 SQL 语句将数据存储到关系数据库中。我们简单看一下 java 中用到的技术。

 

Armed with that information, we'll then continue our discussion of persistence and how it's implemented in object-

 

oriented applications.

有了这些信息,我们就能够继续讨论在 OO 应用中的持久化方案了。

 

 

1.1.1 Relational databases

You, like most other developers, have probably worked with a relational database. Most of us use a relational

 

database every day.

你象其他开发人员一样,大概也用关系数据库,我们许多人每天都用关系数据库。

 

Relational technology is a known quantity, and this alone is sufficient reason for many organizations to choose it.

But to say only this is to pay less respect than is due.

关系数据库技术鼎鼎大名 , 这足以使很多组织选择它。但真的有必要吗?

 

 

Relational databases are entrenched because they're an incredibly flexible and robust approach to data management.

关系数据库能够安身立命是因为它难以置信的灵活性和健壮性

 

Due to the complete and consistent theoretical foundation of the relational data model, relational databases can

 

effectively guarantee and protect the integrity of the data, among other desirable characteristics.

由于其完善的基于关系数据模型理论 , 关系数据库可高效的保证的数据一致性,还有其他引人注目的特性。

 

Some people would even say that the last big invention in computing has been the relational concept for data

 

management as first introduced by E.F. Codd (Codd, 1970) more than three decades ago.

 

有些人甚至说最大的计算机发明是 1970 Code 引入的关系数据库概念 , 距今已经 30 年了

 

Relational database management systems aren't specific to Java, nor is a relational database specific to a

 

particular application.

关系数据库管理系统不是单独为 JAVA 应用的,也不是为特定应用的。

 

This important principle is known as data independence.

这种原则被称为数据独立性。

 

In other words, and we can't stress this important fact enough, data lives longer than any application does.

换句话说,数据比任何应用的生命周期都长。

 

Relational technology provides a way of sharing data among different applications, or among different technologies

 

that form parts of the same application (the transactional engine and the reporting engine, for example).

关系数据库技术提供了在不同应用间,或者应用的不同部分间共享数据的途径。例如事务引擎和报表引擎。

 

Relational technology is a common denominator of many disparate systems and technology platforms. Hence, the

 

relational data is often the common enterprise-wide representation of business entities.

关系技术是一个多项技术和平台的通常称谓,关系数据通常是企业业务对象的表现方式。

 

 

Relational database management systems have SQL-based application programming interfaces; hence, we call today's

 

relational database products SQL database management systems or, when we're talking about particular systems, SQL

 

databases.

关系数据库有基于 SQL 的编程接口。因此,我们称关系数据库为 SQL 数据库系统或者称 SQL 数据库。

 

Before we go inot more detail about the practical aspects of SQL databases, we have mention an important issue:

 

Although marketed as relational, a database system  providing only an SQL data language interface isn't really

 

relational and in many ways isn't even close to the original concept. Naturally, this has led to confusion.

在乡下介绍 SQL 数据库前,先谈一个重要的问题:尽管标识这“关系”, 一个数据库系统仅仅提供 SQL 接口不是真正的“关系”,并

 

且很多不符合最初的概念。自然,这引起了混乱。

 

SQL practitioners blame the relational data model for shortcomings in the SQL language, and relational data

 

management experts blame the SQL standard for being a weak implementation of the relational model and ideals.

 

SQL 实践者抱怨 SQL 原因描述的数据模型的缺点,关系数据专家抱怨 SQL 标准太虚弱。

 

Application developers are stuck somewhere in the middle, with the burden to deliver something that works.

应用开发者夹在中间

 

We'll highlight some important and significant aspects of this issue throughout the book, but generally we'll focus

 

on the practical aspects.

我们将在本书中强调重要的方面,但通常我们聚集在实践方面。

 

If you're interested in more background material, we highly recommend Practical Issues in Database Management: A

 

Reference for the Thinking Practitioner by Fabian Pascal(Pascal,2000).

如果你对更多背景知识感兴趣,我强烈推荐 Practical Issues in Database Management 这本书。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值