本文作者:苏生米沿

本文地址:http://blog.csdn.net/sushengmiyan/article/details/50414652

In this chapter, we focus on the most important part of your system: the databaseschema, where your collection of integrity rules resides—the model of the realworld that you’ve created.

If your application can auction an item only once in the real world, your database schema should guarantee that. If an auction always has a starting price, your database model should include an appropriate constraint.

If data satisfies all integrity rules, the data is consistent, a term you’ll meet again in section11.1.

We also assume that consistent data is correct: everything the database states, either explicitly or implicitly, is true; everything else is false.

If you want to know more aboutthe theory behind this approach, look up the closed-world assumption (CWA).

本章,我们主要集中在你系统中最重要的部分,数据库schema,你的完整性规则驻留的地方---你创建的真实世界的模型。如果在真实世界中你的应用程序只能对一件物品竞价一次,你的数据库schema就应保证这点。如果一个竞拍总有一个开始价格,你的数据库模型应该包括一个适当的约束。如果数据满足所有完整性约束,数据就是一致的,这个术语会在11.1章节再次遇到。

我们还假设一致的数据是正确的,数据库所表述的所有数据,无论是显式的还是隐式的,都是正确的,其它的所有都是错误的。如果你想知道这个理论背后的更多知识,请参考封闭世界假设说(CWA)。

Major new features in JPA 2
 Schema generation and execution of custom SQL scripts during bootstrap is now standardized and can be configured on a persistence unit.
 You can map and customize schema artifacts such as indexes and foreign key names with standard annotations.
 You can map foreign keys/many-to-one associations in composite primary keys with @MapsId as “derived identity.”

JPA2的新特性

在启动的时候生成schema和执行自定义的SQL脚本现在已经标准化了,在持久化单元中就可以进行配置了。

你可以映射和自定义schema物件,像索引和外键,使用标准的注解名称。

你可以映射外键、多对一关系,通过使用@mapsid来定义复合主键这样的衍生主键。

Sometimes you can start a project top-down. There is no existing database schema and maybe not even any data—your application is completely new. 

Many developers like to let Hibernate automatically generate the scripts for a database schema. You’ll probably
also let Hibernate deploy the schema on the test database on your development machine or your continuous build systems for integration testing.

Later, a DBA will take the generated scripts and write an improved and final schema for production deployment.

The first part of this chapter shows you how to improve the schema from within JPA and Hibernate, to make your DBA happy.
At the other end of the spectrum are systems with existing, possibly complex schemas, with years’ worth of data. Your new application is just a small gear in a big machine, and your DBA won’t allow any (sometimes even non-disruptive) changes to the database.

You need a flexible object/relational mapping so you don’t have to twist and bend the Java classes too much when things don’t fit right away.

This will be the subject of the second half of this chapter, including a discussion of composite primary and foreign keys.

有时候,你可以自顶向下的开始一个工程。你的项目工程是全新的,没有现存的数据库shema甚至没有数据。很多开发者喜欢让hibernate来产生数据库的schema的脚本。你可能让hibernate部署你的测试库在你的开发机器上,或者你的集成测试中。稍晚些,DBA就会拿到生成的脚本,改善一下并且写出改善之后的最终产品发布schema。本章的第一部分就给你展示如何提升hibernate和JPA生成的schema,来让你的DBA高兴。

在光谱的另一端就是集成可能是复杂的schema的具有多年数据价值的系统了。

你的新应用就是一个在大机器上的小齿轮。你的DBA不会允许你进行任何的数据库改变(甚至包括非破坏性的)。你需要一个灵活的对象/关系映射,那样的话,你就不需要为不合时宜的事情扭曲或者弯曲你的java实现类,这是本章第二部分的主题,包括讨论一个复合主键和外键。

摘自 hibernate与JPA 第九章。转载请标明来源,谢谢。

复杂和遗留的数据库schema的更多相关文章

  1. 第 9 章 MySQL数据库Schema设计的性能优化

    前言: 很多人都认为性能是在通过编写代码(程序代码或者是数据库代码)的过程中优化出来的,其实这是一个非常大的误区.真正影响性能最大的部分是在设计中就已经产生了的,后期的优化很多时候所能够带来的改善都只 ...

  2. MySQL性能调优与架构设计——第9章 MySQL数据库Schema设计的性能优化

    第9章 MySQL数据库Schema设计的性能优化 前言: 很多人都认为性能是在通过编写代码(程序代码或者是数据库代码)的过程中优化出来的,其实这是一个非常大的误区.真正影响性能最大的部分是在设计中就 ...

  3. 数据库schema设计与优化

    原文地址 1. 前言 对于数据库而言,在日常开发中我们主要的关注点有两块,一个是schema的结构设计,另一个就是索引的优化,这两块是影响我们最终系统结构和性能的关键部分,自然也是我们花费精力最多的部 ...

  4. Flyway, 数据库Schema管理利器

    整天跟数据库打交道的程序员都知道,当数据库的Schema发生改变时是多么痛苦的事情.尤其是一个在不断开发完善的项目,随着需求变化,数据库的schema也会跟着变化,而追踪记录这些变化一向都是费时费力. ...

  5. 数据库Schema两种含义~~

    1.数据库Schema有两种含义,一种是概念上的Schema,指的是一组DDL语句集,该语句集完整地描述了数据库的结构.还有一种是物理上的 Schema,指的是数据库中的一个名字空间,它包含一组表.视 ...

  6. 数据库 schema含义

    数据库Schema有两种含义,一种是概念上的Schema,指的是一组DDL语句集,该语句集完整地描述了数据库的结构.还有一种是物理上的Schema,指的是数据库中的一个名字空间,它包含一组表.视图和存 ...

  7. django “如何”系列9:三合一:利用遗留的数据库、输出csv和输出pdf

    如何集成遗留的数据库 django在适合开发新应用的同时,可以可以集成以前遗留的数据库,下面是如何集成一个已经存在的数据库的流程. 给定你的数据库的参数 你需要告诉django你的数据库连接参数以及数 ...

  8. C#同步SQL Server数据库Schema

    C#同步SQL Server数据库Schema 1. 先写一个sql加工类: using System; using System.Collections.Generic; using System. ...

  9. sqlserver数据库 Schema

    //读取数据库中所有的数据库 USE MASTER DECLARE @is_policy_automation_enabled bit SET @is_policy_automation_enable ...

随机推荐

  1. 【转】如何使用slave_exec_mode优雅的跳过1032 1062的复制错误

    今天线上的主从复制发生1062的错误,使用sql_slave_skip_counter跳过之后,由于后面的事务需要对刚刚的数据进行update,后续造成了新的1032的错误. 后来,无意中发现还有更好 ...

  2. 确定稳定的 Spring Cloud 相关环境版本

    开发部署 Spring Cloud 微服务框架,需要先确定 Spring Cloud 的相关环境版本,主要包含:Spring Cloud.Spring Cloud Netflix.JDK.JRE.Ja ...

  3. [APIO 2012]派遣

    Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿. 在这个帮派里,有一名忍者被称之为Master.除了Master以外,每名忍者都有且仅有一个上级.为 ...

  4. [HNOI2007]最小矩形覆盖

    题目描述 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形,输出所求矩形的面积和四个顶点坐标 输入输出格式 输入格式: 第一行为一个整数n(3<=n<=50000),从第2至第n+1 ...

  5. 【HNOI2017】影魔

    题目描述 影魔,奈文摩尔,据说有着一个诗人的灵魂.事实上,他吞噬的诗人灵魂早已成千上万.千百年来,他收集了各式各样的灵魂,包括诗人.牧师.帝王.乞丐.奴隶.罪人,当然,还有英雄. 每一个灵魂,都有着自 ...

  6. ●Codevs 4158 残缺的字符串

    题链: http://codevs.cn/problem/4158/ 题解: FFT. 定义两个相同长度的字符串s1,s2的距离为 $$dis(s1,s2)=\sum_{i=0}^{len-1}(s1 ...

  7. Codeforces Round#433 简要题解

    来自FallDream的博客,未经允许,请勿转载,谢谢. 我的号自从几个月前姿势水平过低疯狂掉分之后就没动过了  突然想上点分  就打了一场Div1  没想到打到了rank5  一发上橙了,可还行. ...

  8. Thinkphp中的 I 函数(Thinkphp3.2.3版本)

    I 函数的作用是获取系统变量,必要时还可以对变量值进行过滤及强制转化,I 函数的语法格式: I('变量类型.变量名/修饰符',['默认值'],['过滤方法或正则'],['额外数据源']) 一.获取变量 ...

  9. PostgreSQL 查看单表大小

    1. 在数据库中查单个表 select pg_size_pretty(pg_relation_size('table_name')); 2. 查出并按大小排序 SELECT table_schema ...

  10. mysql 拼接

    SELECT  RTRIM(CONCAT(belong_master_ip ,'(',host_name,')')) AS cloudIP  FROM `cloud_master_cfg`