JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-001区分entities and value types
一、介绍
1.这种引用方式不对,但删除时不能级联
要这种引用方式
2.The Bid class could be a problem. In object-oriented modeling, this is marked as a composition (the association between Item and Bid with the diamond). Thus, an Item is the owner of its Bid instances and holds a collection of references. At first, this seems reasonable, because bids in an auction system are useless when the item they
were made for is gone.But what if a future extension of the domain model requires a User#bids collection, containing all bids made by a particular User ? Right now, the association between Bid and User is unidirectional; a Bid has a bidder reference. What if this was bidirectional?
In that case, you have to deal with possible shared references to Bid instances, so the Bid class needs to be an entity. It has a dependent life cycle, but it must have its own identity to support (future) shared references.
3.编写实体类和值对象时,注意以下3点:
(1)Shared references—Avoid shared references to value type instances when you write your POJO classes.
(2)Life cycle dependencies—If a User is deleted, its Address dependency has to be deleted as well.
(3)Identity—Entity classes need an identifier property in almost all cases. Value type classes (and of course JDK classes such as String and Integer ) don’t have an identifier property, because instances are identified through the owning entity.
JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-001区分entities and value types的更多相关文章
- JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-003映射实体时的可选操作(<delimited-identifiers/>、PhysicalNamingStrategy、PhysicalNamingStrategyStandardImpl、、、)
一.自定义映射的表名 1. @Entity @Table(name = "USERS") public class User implements Serializable { / ...
- JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-002identity详解
一.简介 1.You now have three methods for distinguishing references: Objects are identical if they occ ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-001Mapping basic properties(@Basic、@Access、access="noop"、@Formula、@ColumnTransformer、@Generated、 @ColumnDefaul、@Temporal、@Enumerated)
一.简介 在JPA中,默认所有属性都会persist,属性要属于以下3种情况,Hibernate在启动时会报错 1.java基本类型或包装类 2.有注解 @Embedded 3.有实现java.io. ...
- JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-006Mixing inheritance strategies(@SecondaryTable、@PrimaryKeyJoinColumn、<join fetch="select">)
一.结构 For example, you can map a class hierarchy to a single table, but, for a particular subclass, s ...
- JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-003Table per concrete class with unions(@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)、<union-subclass>)
一.代码 1. package org.jpwh.model.inheritance.tableperclass; import org.jpwh.model.Constants; import ja ...
- JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-002Table per concrete class with implicit polymorphism(@MappedSuperclass、@AttributeOverride)
一.结构 二.代码 1. package org.jpwh.model.inheritance.mappedsuperclass; import javax.persistence.MappedSup ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-007UserTypes的用法(@org.hibernate.annotations.Type、@org.hibernate.annotations.TypeDefs、CompositeUserType、DynamicParameterizedType、、、)
一.结构 二.Hibernate支持的UserTypes接口 UserType —You can transform values by interacting with the plain JD ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-006类型转换器( @Converter(autoApply = true) 、type="converter:qualified.ConverterName" )
一.结构 二.代码 1. package org.jpwh.model.advanced; import java.io.Serializable; import java.math.BigDecim ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-005控制类型映射(Nationalized、@LOB、@org.hibernate.annotations.Type)
一.简介 1. 2. 3. 4. to override this default mapping. The JPA specification has a convenient shortcut a ...
随机推荐
- JavaScript设计模式与开发实践——JavaScript的多态
“多态”一词源于希腊文polymorphism,拆开来看是poly(复数)+ morph(形态)+ ism,从字面上我们可以理解为复数形态. 多态的实际含义是:同一操作作用于不同的对象上面,可以产生不 ...
- 双系统下利用MbrFix.exe卸载LINUX系统
前言: 不少同学笔记本都装的有双系统,一般都是LIUNX和WINDOWS的两个系统(由于以前对电脑各种无知)装了双系统,再次,小编就不在阐述双系统地各种不便,再次就强调一下,假若要卸载LINUX的话 ...
- P2763: [JLOI2011]飞行路线
然而WA了呀,这道分层图,也是不明白为什么WA了=-= ; maxn=; points=; type node=record f,t,l:longint; end; var n,m,k,i,j,u,v ...
- tomcat设置内存大小
-Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m
- 【每日scrum】NO.2
1.今天找到了铁大电子地图. 2.需求分析未完成,进度有点慢.
- [Z] 深入浅出 Systemd
1. Systemd 的简介和特点 Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度.systemd 和 u ...
- 【BZOJ】【1041】【HAOI2008】圆周上的点
数学 orz hzwer 完全不会做…… 很纠结啊,如果将来再遇到这种题,还是很难下手啊…… 引用题解: [分析]: 样例图示: 首先,最暴力的算法显而易见:枚举x轴上的每个点,带入圆的方程,检查是否 ...
- 【BZOJ】【2245】【SDOI2011】工作安排
网络流/费用流 裸题吧……直接建模就好了……所谓的“分段函数”就是吓唬你的,其实就是对于每个人分开建几条流量不同.费用不同的弧而已. 对每种产品,连S->i ,(c[i],0):对每个工作人员 ...
- Sea.js入门
本文只是seajs的入门贴.要详细了解,请看GitHub主页上的相关链接,精彩不断,精选几篇: 前端模块化开发的价值 前端模块化开发的历史 ID和路径匹配原则 与RequireJS的异同 模块的加载启 ...
- datepicker,结束时间必须大于开始时间
$('#js-start-time').datepicker({ dateFormat:'yy-mm-dd', onSelect: function( startDate ) { var $start ...