JavaPersistenceWithHibernate读书笔记(2)
1.2 The paradigm mismatch
can be broken into several parts-->we will examine one at a time-->start with a example that is problem free --> mismatch appear.
User: represent information about a user of the system.
BillingDetails: represent information about the user's billing details.
public class User {
private String username;
private String name;
private String address;
private Set billingDetails;
// Accessor methods (getter/setter), business methods, etc.
...
}
public class BillingDetails {
private String accountNumber;
private String accountName;
private String accountType;
private User user;
// Accessor methods (getter/setter), business methods, etc.
...
}
with the following SQL schema:
create table USERS (
USERNAME varchar(15) not null primary key,
NAME varchar(50) not null,
ADDRESS varchar(100)
)
create table BILLING_DETAILS (
ACCOUNT_NUMBER varchar(10) not null primary key,
ACCOUNT_NAME varchar(50) not null,
ACCOUNT_TYPE varchar(2) not null,
USERNAME varchar(15) foreign key references user
)
relationship between the two entities is represented as the foreign key, USERNAME,in BILLING_DETAILS.
now it's straightforward to write JDBC code to insert,update,and delete information about users billing details.
make paradigm mismatch visible --> since address as a simple String,other classes will also carry address info -->create a separate Address class.
Should we also add an ADDRESS table?Not necessarily.It's common to keep address info in the USERS table(基于什么考虑要把这个ADDRESS也放进Users表里?a table join isnt needed),in individual columns.
Basically, we have the choice of adding either several columns or a single column (of a new SQL datatype). This is clearly a problem of granularity.
1.2.1 The problem of granularity
Granularity refers to the relative size of the types you’re working with.
For these and whatever other reasons, use of UDTs or Java types inside an SQL database isn’t common practice in the industry at this time.
Our pragmatic solution for this problem has several columns of built-in vendor-defined SQL types (such as boolean, numeric, and string datatypes). TheUSERS table is usually defined as follows:
create table USERS (
USERNAME varchar(15) not null primary key,
NAME varchar(50) not null,
ADDRESS_STREET varchar(50),
ADDRESS_CITY varchar(15),
ADDRESS_STATE varchar(15),
ADDRESS_ZIPCODE varchar(5),
ADDRESS_COUNTRY varchar(15)
)
Classes in our domain model come in a range of different levels of granularity-- from coarse-grained entity classes like User, to finer-grained classes like Address, down to simple String-valued properties such as zipcode. In contrast, just two levels of granularity are visible at the level of the SQL database: tables such as USERS, and columns such as ADDRESS_ZIPCODE.
1.2.2 The problem of subtypes
分享到:
相关推荐
【标题】"java读书笔记笔记笔记笔记笔记笔记" 暗示了这是一份关于Java编程语言的学习笔记,可能包含了作者在阅读Java相关书籍时所做的重要记录和理解。笔记通常涵盖了语言的基础概念、核心特性、类与对象、内存管理...
学生读书笔记共享-学生读书笔记共享系统-学生读书笔记共享系统源码-学生读书笔记共享管理系统-学生读书笔记共享管理系统java代码-学生读书笔记共享系统设计与实现-基于springboot的学生读书笔记共享系统-基于Web的...
总之,《深入浅出Hibernate》读书笔记涵盖了实体对象生命周期的转换、实体对象的识别机制以及Hibernate的多级缓存策略,这些都是理解并有效使用Hibernate的关键点。通过深入学习这些概念,开发者能够更好地掌握...
学生读书笔记共享-学生读书笔记共享系统-学生读书笔记共享系统源码-学生读书笔记共享管理系统-学生读书笔记共享管理系统java代码-学生读书笔记共享系统设计与实现-基于springboot的学生读书笔记共享系统-基于Web的...
hibernate读书笔记,里面有一些实例和解说,是自己整理的,非常适合开发时做参考
Hibernate学习笔记整理 以下是 Hibernate 框架的详细知识点: Hibernate 介绍 Hibernate 是一个 ORM(Object-Relational Mapping)框架,用于将 Java 对象映射到数据库表中。它提供了一个简洁的方式来访问和操作...
java虚拟机读书笔记,主要描述阅读Java虚拟机核心技术的描述。
【Java相关课程系列笔记之十四Hibernate学习笔记】 Hibernate是一个开源的对象关系映射(ORM)框架,它极大地简化了Java应用程序对数据库的操作。本笔记将详细阐述Hibernate的核心概念、使用方法和特性。 一、...
通过阅读《Java游戏编程读书笔记》这本书,你可以深入了解这些概念并学习如何将它们应用到实际项目中。文档中的内容可能涵盖了Java游戏开发的基本原理、代码示例、最佳实践以及常见问题的解决方案。通过深入学习和...
读书笔记:《数据结构与算法分析 java语言描述》 读书笔记
读书笔记:「数据结构与算法分析Java语言描述」读书笔记。
### 马士兵Java框架Hibernate学习笔记 #### 一、HelloWorld - **知识点概述**: - **项目搭建**:介绍了如何从零开始搭建一个简单的Hibernate项目。 - **环境配置**:包括了如何配置MySQL数据库、创建必要的表...
计算机技术的读书笔记10篇计算机技术的读书笔记10篇计算机技术的读书笔记10篇计算机技术的读书笔记10篇计算机技术的读书笔记10篇